From c90b1772849c53fc118ac38c93dedecd81d46a29 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 24 Sep 2024 16:08:41 -0400 Subject: [PATCH] feat: SQLite3::ForkSafety.suppress_warnings! For frameworks like Rails where it's expected to sometimes fork with open writable connections. --- lib/sqlite3/fork_safety.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/sqlite3/fork_safety.rb b/lib/sqlite3/fork_safety.rb index a39ce159..69cf6ac3 100644 --- a/lib/sqlite3/fork_safety.rb +++ b/lib/sqlite3/fork_safety.rb @@ -17,6 +17,7 @@ def _fork @databases = [] @mutex = Mutex.new + @suppress = false class << self def hook! @@ -30,7 +31,7 @@ def track(database) end def discard - warned = false + warned = @suppress @databases.each do |db| next unless db.weakref_alive? @@ -49,6 +50,11 @@ def discard end @databases.clear end + + # Call to suppress the fork-related warnings. + def suppress_warnings! + @suppress = true + end end end end