EctoLibSql.State (EctoLibSql v0.8.8)

Copy Markdown View Source

Maintains the connection state for a LibSQL database connection.

This struct tracks the current connection state including the connection ID, active transaction ID (if any), connection mode, and sync settings.

Fields

  • :conn_id - Unique identifier for the connection (required)
  • :trx_id - Transaction ID if a transaction is active, nil otherwise
  • :mode - Connection mode (:local, :remote, or :remote_replica)
  • :sync - Sync mode for replicas (:enable_sync or :disable_sync)

Connection Modes

  • :local - Local SQLite file
  • :remote - Direct connection to remote Turso database
  • :remote_replica - Local SQLite file with remote sync enabled

Summary

Types

Connection mode for LibSQL database connections.

Sync mode for replica connections.

t()

Connection state struct.

Functions

Detects the connection mode based on provided options.

Detects the sync mode based on provided options.

Types

mode()

@type mode() :: :local | :remote | :remote_replica | :unknown

Connection mode for LibSQL database connections.

sync_mode()

@type sync_mode() :: :enable_sync | :disable_sync

Sync mode for replica connections.

t()

@type t() :: %EctoLibSql.State{
  conn_id: String.t(),
  mode: mode() | nil,
  sync: sync_mode() | nil,
  trx_id: String.t() | nil
}

Connection state struct.

Functions

detect_mode(opts)

@spec detect_mode(Keyword.t()) :: mode()

Detects the connection mode based on provided options.

Examples

iex> EctoLibSql.State.detect_mode(database: "local.db")
:local

iex> EctoLibSql.State.detect_mode(uri: "libsql://...", auth_token: "...")
:remote

iex> EctoLibSql.State.detect_mode(database: "local.db", uri: "libsql://...", auth_token: "...", sync: true)
:remote_replica

detect_sync(opts)

@spec detect_sync(Keyword.t()) :: sync_mode()

Detects the sync mode based on provided options.

Returns :enable_sync if sync is explicitly set to true, :disable_sync otherwise.

Examples

iex> EctoLibSql.State.detect_sync(sync: true)
:enable_sync

iex> EctoLibSql.State.detect_sync(sync: false)
:disable_sync

iex> EctoLibSql.State.detect_sync([])
:disable_sync