Class: ActiveRecord::ConnectionAdapters::BeagleTursoAdapter::Client
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::BeagleTursoAdapter::Client
- Defined in:
- lib/active_record/connection_adapters/beagle_turso_adapter.rb
Overview
Adapts a Beagle::Turso::Database + its connected Connection to the subset
of the sqlite3 gem's Database surface that SQLite3Adapter pokes at.
The execution methods (+query_result+, execute, execute_batch,
last_insert_rowid) are the real work. The rest are shims: the adapter's
configure_connection sets PRAGMAs via raw_connection.foo = value and
calls a couple of sqlite3-specific lifecycle methods that libsql neither
needs nor supports; we accept and no-op those so connect/configure runs
cleanly.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Instance Method Summary collapse
-
#busy_handler_timeout=(_) ⇒ Object
--- sqlite3-gem lifecycle shims the SQLite3Adapter drives --- configure_connection only touches this when config is set.
-
#close ⇒ Object
Release the beagle-turso session eagerly rather than waiting for GC.
-
#closed? ⇒ Boolean
connected? => !(@raw_connection.nil? || @raw_connection.closed?).
- #execute(sql, params) ⇒ Object
- #execute_batch(sql) ⇒ Object
-
#initialize(database) ⇒ Client
constructor
A new instance of Client.
- #last_insert_rowid ⇒ Object
-
#method_missing(name, *args) ⇒ Object
configure_connection applies DEFAULT_PRAGMAS via
raw_connection.foo = v. - #pull ⇒ Object
-
#push ⇒ Object
--- sync passthrough (Database-level) ---.
-
#query_result(sql, params) ⇒ Object
--- execution surface used by BeagleTursoAdapter#perform_query ---.
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
-
#rollback ⇒ Object
SQLite3Adapter#reconnect calls this when reusing a live connection.
Constructor Details
#initialize(database) ⇒ Client
Returns a new instance of Client.
94 95 96 97 98 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 94 def initialize(database) @database = database @connection = database.connect @closed = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
configure_connection applies DEFAULT_PRAGMAS via raw_connection.foo = v.
libsql manages journalling/locking itself, so accept and ignore them.
199 200 201 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 199 def method_missing(name, *args) name.to_s.end_with?("=") ? nil : super end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
92 93 94 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 92 def connection @connection end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
92 93 94 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 92 def database @database end |
Instance Method Details
#busy_handler_timeout=(_) ⇒ Object
--- sqlite3-gem lifecycle shims the SQLite3Adapter drives --- configure_connection only touches this when config is set.
167 168 169 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 167 def busy_handler_timeout=(_) nil end |
#close ⇒ Object
Release the beagle-turso session eagerly rather than waiting for GC. A synced Database holds a server-side sync session open; without an explicit close each ActiveRecord disconnect/reconnect (e.g. verify!/db:prepare) leaked one, accumulating on the remote until it reported "database is busy". Close the connection first, then the database (which ends the sync session). Idempotent.
-- the session would leak silently (SQLite3Adapter#disconnect! swallows the exception). The ensure guarantees the database (session) close runs even if the connection close raises, and @closed reflects reality.
185 186 187 188 189 190 191 192 193 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 185 def close return if @closed begin @connection.close ensure @database.close @closed = true end end |
#closed? ⇒ Boolean
connected? => !(@raw_connection.nil? || @raw_connection.closed?)
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 171 def closed? = @closed # Release the beagle-turso session eagerly rather than waiting for GC. # A *synced* Database holds a server-side sync session open; without an # explicit close each ActiveRecord disconnect/reconnect (e.g. # verify!/db:prepare) leaked one, accumulating on the remote until it # reported "database is busy". Close the connection first, then the # database (which ends the sync session). Idempotent. # # @closed is only flipped true AFTER both closes have run: if # @connection.close raised and we had set @closed up front, the ensure'd # @database.close would be skipped yet closed? would already report true # -- the session would leak silently (SQLite3Adapter#disconnect! swallows # the exception). The ensure guarantees the database (session) close runs # even if the connection close raises, and @closed reflects reality. |
#execute(sql, params) ⇒ Object
157 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 157 def execute(sql, params) = connection.execute(sql, params) |
#execute_batch(sql) ⇒ Object
158 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 158 def execute_batch(sql) = connection.execute_batch(sql) |
#last_insert_rowid ⇒ Object
159 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 159 def last_insert_rowid = connection.last_insert_rowid |
#pull ⇒ Object
163 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 163 def pull = database.pull |
#push ⇒ Object
--- sync passthrough (Database-level) ---
162 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 162 def push = database.push |
#query_result(sql, params) ⇒ Object
--- execution surface used by BeagleTursoAdapter#perform_query ---
148 149 150 151 152 153 154 155 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 148 def query_result(sql, params) columns, rows = connection.query_result(sql, params) if columns.empty? && rows.empty? && (match = BARE_PRAGMA_READ_REGEX.match(sql)) [[match[1]], [[0]]] else [columns, rows] end end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
203 204 205 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 203 def respond_to_missing?(name, include_private = false) name.to_s.end_with?("=") || super end |
#rollback ⇒ Object
SQLite3Adapter#reconnect calls this when reusing a live connection.
195 |
# File 'lib/active_record/connection_adapters/beagle_turso_adapter.rb', line 195 def rollback = execute("ROLLBACK", []) |