# `EctoLibSql.State`
[🔗](https://github.com/ocean/ecto_libsql/blob/v0.9.1/lib/ecto_libsql/state.ex#L1)

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

# `mode`

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

Connection mode for LibSQL database connections.

# `sync_mode`

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

Sync mode for replica connections.

# `t`

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

Connection state struct.

# `detect_mode`

```elixir
@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`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
