glite/config

Settings for opening a connection.

Every limit has a fixed upper bound. Reaching one is an error, never a silent truncation.

let config =
  config.new("/var/lib/modorra/state.db")
  |> config.call_timeout_ms(5000)
  |> config.max_rows(1000)

Types

Settings for one connection.

pub type Config {
  Config(
    path: String,
    journal_mode: JournalMode,
    synchronous: SynchronousMode,
    foreign_keys: Bool,
    busy_timeout_ms: Int,
    call_timeout_ms: Int,
    interrupt_grace_ms: Int,
    max_rows: Int,
    max_batch: Int,
    max_queue: Int,
    pragmas: List(#(String, String)),
  )
}

Constructors

  • Config(
      path: String,
      journal_mode: JournalMode,
      synchronous: SynchronousMode,
      foreign_keys: Bool,
      busy_timeout_ms: Int,
      call_timeout_ms: Int,
      interrupt_grace_ms: Int,
      max_rows: Int,
      max_batch: Int,
      max_queue: Int,
      pragmas: List(#(String, String)),
    )

    Arguments

    path

    Database file path, or “:memory:”.

    foreign_keys

    Enforce FOREIGN KEY constraints.

    busy_timeout_ms

    How long SQLite waits for another connection’s lock before returning Busy. Must be shorter than call_timeout_ms.

    call_timeout_ms

    How long a caller waits for a call to finish before interrupting it and returning Timeout.

    interrupt_grace_ms

    After interrupting a call, how long the caller waits for SQLite to stop before giving up on it.

    max_rows

    Most rows one query may return.

    max_batch

    Most parameter sets one exec_many call may take.

    max_queue

    Most calls that may wait for the connection at once.

    pragmas

    Extra PRAGMAs, applied in order after the settings above.

How SQLite keeps its rollback information.

pub type JournalMode {
  Wal
  Delete
  Memory
  Off
}

Constructors

  • Wal

    Write-ahead log: readers don’t block the writer. The default for files.

  • Delete

    Rollback journal, deleted after each transaction.

  • Memory

    Rollback journal in memory. The only mode an in-memory database has.

  • Off

    No journal: no crash recovery and no rollback.

When SQLite waits for data to reach the disk.

pub type SynchronousMode {
  Full
  Normal
  SyncOff
}

Constructors

  • Full

    Sync on every commit. A committed transaction survives a power cut. The default.

  • Normal

    Sync less often. In WAL mode the last commits can be lost on a power cut, but the database is never corrupted.

  • SyncOff

    Never sync. A power cut can corrupt the database.

Values

pub fn busy_timeout_ms(config: Config, ms: Int) -> Config
pub fn call_timeout_ms(config: Config, ms: Int) -> Config
pub fn foreign_keys(config: Config, enabled: Bool) -> Config
pub fn interrupt_grace_ms(config: Config, ms: Int) -> Config
pub fn journal_mode(config: Config, mode: JournalMode) -> Config
pub fn max_batch(config: Config, limit: Int) -> Config
pub fn max_queue(config: Config, limit: Int) -> Config
pub fn max_rows(config: Config, limit: Int) -> Config
pub fn memory() -> Config

Settings for a private in-memory database, otherwise the same as new.

pub fn new(path: String) -> Config

Settings for a database file: WAL, full sync, foreign keys on, a 5 s busy timeout, a 10 s call timeout, and at most 10,000 rows per query, 10,000 parameter sets per batch and 1,000 waiting calls.

pub fn pragma(
  config: Config,
  name: String,
  value: String,
) -> Config

Add a PRAGMA to run when the database opens, after the ones before it. The name must be lowercase letters and underscores, and the value a number or a bare word, such as pragma("cache_size", "-8000").

pub fn synchronous(
  config: Config,
  mode: SynchronousMode,
) -> Config
✨ Search Document