class ObjectFramework::SQLite::Storage
Optional file-backed SQLite adapter, requiring the sqlite3 gem. Each transaction owns a connection with foreign keys enabled and FULL synchronization. Uses DELETE journaling, IMMEDIATE writes, and DEFERRED reads. Commit failures are propagated without automatic retry.
Attributes
Public Class Methods
Source
# File lib/object_framework/sqlite/storage.rb, line 34 def initialize(path:, schema:, lock_timeout: 1) raise ConfigurationError, "SQLite requires a database file path" if path.to_s.empty? || path.to_s == ":memory:" raise ConfigurationError, "Lock timeout must be positive" unless lock_timeout.is_a?(Numeric) && lock_timeout.positive? @path, @schema, @lock_timeout = File.expand_path(path), schema.finalize!, lock_timeout @mutex, @connections, @closed = Mutex.new, 0, false migrate end
Finalizes schema and migrates the database at path. In-memory paths are rejected. lock_timeout bounds lock waiting in seconds; execution cancellation and deadlines may interrupt that wait earlier.
Public Instance Methods
Source
# File lib/object_framework/sqlite/storage.rb, line 44 def begin_transaction(mode:) begin_transaction_for(mode:, context: ExecutionContext.new) end
Source
# File lib/object_framework/sqlite/storage.rb, line 48 def begin_transaction_for(mode:, context:) @mutex.synchronize { raise Unavailable, "Storage is closed" if @closed } context.cancellation.check! database = connect(cancellation: context.cancellation) Transaction.new(database:, schema: @schema, mode:, cancellation: context.cancellation, closed: -> { disconnected }) rescue Exception if database && !database.closed? database.close disconnected end raise end
Source
# File lib/object_framework/sqlite/storage.rb, line 64 def close @mutex.synchronize { @closed = true } end
Rejects new transactions. Already-open transactions retain ownership of their connections until they close. Stop applications first.
Source
# File lib/object_framework/sqlite/storage.rb, line 42 def open_connection_count; @mutex.synchronize { @connections }; end