TimelessMetrics.DB (timeless_metrics v6.6.7)

Copy Markdown View Source

SQLite connection manager with a single writer and pooled readers.

Uses WAL mode for concurrent reads during writes. The writer is serialized through a GenServer to respect SQLite's single-writer constraint.

Summary

Functions

Create a consistent backup of this database using VACUUM INTO.

Returns a specification to start this module under a supervisor.

Get the database path.

Execute a read query using a reader connection from the pool.

Execute a write query (INSERT, UPDATE, DELETE) through the serialized writer.

Execute multiple write queries in a single transaction.

Types

query_result()

@type query_result() :: {:ok, [row()]} | {:error, term()}

row()

@type row() :: [term()]

server()

@type server() :: GenServer.server()

Functions

backup(db, target_path)

@spec backup(server(), Path.t()) :: query_result()

Create a consistent backup of this database using VACUUM INTO.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

db_path(db)

@spec db_path(server()) :: String.t() | {:error, term()}

Get the database path.

read(db, sql, params \\ [])

@spec read(server(), String.t(), list()) :: query_result()

Execute a read query using a reader connection from the pool.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

write(db, sql, params \\ [])

@spec write(server(), String.t(), list()) :: query_result()

Execute a write query (INSERT, UPDATE, DELETE) through the serialized writer.

write_transaction(db, fun)

@spec write_transaction(server(), (term() -> result)) ::
  {:ok, result} | {:error, term()}
when result: term()

Execute multiple write queries in a single transaction.