Skip to main content

Module connection

Module connection 

Source
Expand description

SqliteConnection — Limbo-backed implementation of oxisql_core::Connection.

§Concurrency model

limbo::Connection is internally Arc<Mutex<Arc<limbo_core::Connection>>> with unsafe impl Send + Sync, so it is safe to clone and share across async tasks. SqliteConnection is a thin newtype that holds:

  • conn: limbo::Connection — the Limbo connection handle.
  • txn_lock: Arc<tokio::sync::Mutex<()>> — a guard that prevents two async tasks from issuing BEGIN concurrently on the same logical connection. SQLite does not support nested transactions, so only one task at a time may hold a transaction.
  • path: String — the path supplied to Builder::new_local, retained for diagnostics.

§Affected-row count

After each DML statement we call conn.changes() to read the row count that was committed by the most-recent write transaction. DDL statements and BEGIN/COMMIT/ROLLBACK leave the counter at 0, which is the correct contract per OxiSQL and sqlite3_changes() semantics.

§Parameter binding

OxiSQL passes $1, $2, … positional parameters. SQLite / Limbo expects ? placeholders. types::rewrite_params performs a quote-aware translation before each statement is prepared.

§Schema introspection

Connection::tables queries sqlite_master. Connection::columns uses PRAGMA table_info. Connection::indexes parses sqlite_master DDL (PRAGMA index_list/index_info are not yet implemented in Limbo 0.0.22). Connection::foreign_keys uses PRAGMA foreign_key_list — the engine now surfaces FK metadata from its in-memory schema.

§Transactions

Connection::transaction issues BEGIN and returns a SqliteTransaction that wraps the same limbo::Connection. The transaction holds a guard on txn_lock so that no other task can start a concurrent BEGIN. Dropping SqliteTransaction without calling commit or rollback will execute ROLLBACK (best-effort, via Drop).

§Prepared-statement cache

All DML and DDL statements pass through an LRU cache keyed by the rewritten SQL (after $N? translation). The cache holds up to STMT_CACHE_CAPACITY (128) compiled limbo::Statement entries per connection (shared across clones of the same connection via Arc<StdMutex<…>>).

On a cache hit the existing limbo::Statement is taken out of the cache, executed via Statement::execute() (which calls reset() before binding), and returned to the cache after execution. Statement::reset() now also zeroes Program::n_change (fixed in oxisqlite-core), so cached statement reuse produces correct per-execution change counts.

§ROLLBACK

SqliteTransaction::rollback() executes the SQL string "ROLLBACK" against the engine, exactly mirroring how commit() executes "COMMIT". The engine emits an AutoCommit { auto_commit: true, rollback: true } VDBE instruction that discards all pending changes. The Drop impl also fires a best-effort ROLLBACK when the transaction is dropped without an explicit commit() or rollback().

§Prepared-statement reuse (via SqlitePrepared)

Limbo’s Statement is consumed after a single execute/query cycle. Our PreparedStatement wrapper therefore re-prepares on every call. The API contract (parse-once, bind-many) is satisfied at the OxiSQL trait level even though Limbo does not yet expose a stable compiled-statement cache.

Structs§

SqliteConnection
A Limbo-backed SQLite connection implementing Connection.
SqlitePrepared
A prepared statement backed by the connection-level LRU cache.
SqliteTransaction
A SQLite transaction backed by raw BEGIN/COMMIT/ROLLBACK statements.