Skip to content

Connection

One independent SQLite connection owned by a Database.

Connections retain independent transactions, snapshots, TEMP schemas, busy timeouts, and connection-local PRAGMAs. Closing one connection leaves the database and sibling connections usable.

Connection.query(self, sql: 'str', params: 'Bindings' = ()) -> 'Rows'

Section titled “Connection.query(self, sql: 'str', params: 'Bindings' = ()) -> 'Rows'”

Run exactly one observational SQLite statement and return rows.

State-changing intent is refused before it takes effect. EXPLAIN is observational; known getter PRAGMAs are observational; unknown PRAGMAs are conservatively refused as state-changing. Results are bounded by the connection’s maximum_rows.

Connection.execute(self, sql: 'str', params: 'Bindings' = ()) -> 'ExecuteResult'

Section titled “Connection.execute(self, sql: 'str', params: 'Bindings' = ()) -> 'ExecuteResult'”

Run exactly one state-changing SQLite statement.

Observational intent is refused before it takes effect. Returns an ExecuteResult whose last_insert_id is present only when this direct INSERT or REPLACE changed the connection’s row ID. SQL transaction control is never accepted here; transaction() owns that lifecycle.

Connection.transaction(self, *, mode: 'TransactionMode' = 'immediate') -> '_Transaction'

Section titled “Connection.transaction(self, *, mode: 'TransactionMode' = 'immediate') -> '_Transaction'”

Begin one managed transaction and return its context manager.

The default mode is immediate. The scope commits only on successful completion and always attempts rollback after a failure.

Connection.status(self) -> 'ConnectionStatus'

Section titled “Connection.status(self) -> 'ConnectionStatus'”

Return a typed ConnectionStatus of connection-owned state only.

Close this connection only. Idempotent. Refused while a managed transaction on this connection is active.