Tursox.Connection (tursox v0.2.1)

Copy Markdown View Source

A sequential connection derived from one Tursox.Database resource.

Closing the parent database safely invalidates this resource. Mutable native operations are serialized per connection; independent connections do not use a global lock.

Summary

Functions

Returns whether this connection is currently in autocommit mode.

Begins a deferred, immediate, exclusive, or MVCC concurrent transaction.

Flushes dirty connection pages to the journal.

Runs a tested WAL/MVCC checkpoint pragma.

Logically closes a connection. It is safe to call repeatedly.

Commits the active transaction.

Executes one bound SQL statement and discards execution metadata.

Executes all statements in a SQL batch without bound parameters.

Executes one bound SQL statement and returns affected-row metadata.

Returns the row ID from the most recent successful insert.

Loads a native Turso extension into this connection.

Runs a validated pragma query and returns ordered row lists.

Runs an argument-bearing pragma without interpolating caller-controlled SQL.

Updates a validated pragma and returns any ordered result rows.

Prepares a real native statement owned by this connection.

Prepares and starts a bounded native cursor convenience query.

Retries a complete transaction callback after classified conflicts.

Rolls back the active transaction.

Sets and verifies the experimental MVCC checkpoint threshold.

Returns :idle in autocommit mode and :transaction otherwise.

Runs a rollback-safe transaction callback.

Types

t()

@opaque t()

Functions

autocommit?(connection)

@spec autocommit?(t()) :: {:ok, boolean()} | {:error, Tursox.Error.t()}

Returns whether this connection is currently in autocommit mode.

begin(connection, opts \\ [])

Begins a deferred, immediate, exclusive, or MVCC concurrent transaction.

cache_flush(connection)

@spec cache_flush(t()) :: :ok | {:error, Tursox.Error.t()}

Flushes dirty connection pages to the journal.

checkpoint(connection, mode \\ :passive)

Runs a tested WAL/MVCC checkpoint pragma.

close(connection)

@spec close(t()) :: :ok

Logically closes a connection. It is safe to call repeatedly.

commit(connection)

Commits the active transaction.

execute(connection, sql, params \\ [])

@spec execute(t(), String.t(), term()) :: :ok | {:error, Tursox.Error.t()}

Executes one bound SQL statement and discards execution metadata.

execute_batch(connection, sql)

@spec execute_batch(t(), String.t()) :: :ok | {:error, Tursox.Error.t()}

Executes all statements in a SQL batch without bound parameters.

execute_result(connection, sql, params \\ [])

@spec execute_result(t(), String.t(), term()) ::
  {:ok, Tursox.Result.t()} | {:error, Tursox.Error.t()}

Executes one bound SQL statement and returns affected-row metadata.

last_insert_rowid(connection)

@spec last_insert_rowid(t()) :: {:ok, integer()} | {:error, Tursox.Error.t()}

Returns the row ID from the most recent successful insert.

load_extension(connection, path)

@spec load_extension(t(), String.t()) :: :ok | {:error, Tursox.Error.t()}

Loads a native Turso extension into this connection.

The database must be opened with unsafe_features: [:runtime_extensions]. Native libraries execute arbitrary code inside the BEAM process. SQLite ABI extensions are not automatically Turso ABI extensions.

pragma_query(connection, name)

@spec pragma_query(t(), atom() | String.t()) ::
  {:ok, [[term()]]} | {:error, Tursox.Error.t()}

Runs a validated pragma query and returns ordered row lists.

pragma_query(connection, name, argument)

@spec pragma_query(
  t(),
  atom() | String.t(),
  {:identifier, String.t()} | non_neg_integer() | String.t()
) :: {:ok, [[term()]]} | {:error, Tursox.Error.t()}

Runs an argument-bearing pragma without interpolating caller-controlled SQL.

Use {:identifier, name} for table/index arguments. Non-negative integers support bounded integrity checks, and strings are safely quoted for structured engine arguments such as CDC modes.

pragma_update(connection, name, value)

@spec pragma_update(t(), atom() | String.t(), term()) ::
  {:ok, [[term()]]} | {:error, Tursox.Error.t()}

Updates a validated pragma and returns any ordered result rows.

prepare(connection, sql)

@spec prepare(t(), String.t()) ::
  {:ok, Tursox.Statement.t()} | {:error, Tursox.Error.t()}

Prepares a real native statement owned by this connection.

query(connection, sql, params \\ [])

@spec query(t(), String.t(), term()) ::
  {:ok, Tursox.Cursor.t()} | {:error, Tursox.Error.t()}

Prepares and starts a bounded native cursor convenience query.

retry_transaction(connection, fun, opts \\ [])

Retries a complete transaction callback after classified conflicts.

rollback(connection)

Rolls back the active transaction.

set_mvcc_checkpoint_threshold(connection, threshold)

Sets and verifies the experimental MVCC checkpoint threshold.

status(connection)

@spec status(t()) :: {:ok, :idle | :transaction} | {:error, Tursox.Error.t()}

Returns :idle in autocommit mode and :transaction otherwise.

transaction(connection, fun, opts \\ [])

Runs a rollback-safe transaction callback.