kura_pool_sqlite (kura_sqlite v0.2.5)

View Source

SQLite pool implementation. Maintains N pre-opened esqlite3 database connections in an ETS-tracked free list. Each checkout/2 hands out a connection; checkin/2 returns it.

Pool state

One ETS table per pool, named after the pool atom. Holds:

  • {available, [esqlite3:esqlite3()]} - free connections.
  • {checked_out, #{esqlite3:esqlite3() => pid()}} - leased + owner.
  • {db_path, binary()} - the database path or :memory: URI.

pool_size from start_pool/2 opts pre-opens N connections.

Example

{ok, _Pid} = kura_pool_sqlite:start_pool(my_pool, #{
    database => <<":memory:">>,
    pool_size => 4
}).

Notes vs PG

Unlike pgo's holder-ETS pattern, SQLite has no socket and no server, so a connection is simply an open database handle. The pool's only job is bounding the count of simultaneously open handles and pairing checkout with checkin.

Summary

Functions

SQLite 3.45 capability set as shipped by esqlite. Excludes PG-only features (advisory_locks, listen_notify, arrays). RETURNING is included since 3.35.

Functions

capabilities()

-spec capabilities() -> kura_capabilities:capability_set().

SQLite 3.45 capability set as shipped by esqlite. Excludes PG-only features (advisory_locks, listen_notify, arrays). RETURNING is included since 3.35.

checkin(Name, Token)

-spec checkin(kura_pool:name(), kura_pool:token()) -> ok.

checkout(Name, Opts)

-spec checkout(kura_pool:name(), kura_pool:checkout_opts()) ->
                  {ok, kura_pool:conn(), kura_pool:token()} | {error, term()}.

give_away/3

-spec give_away(kura_pool:token(), pid(), term()) -> ok | {error, term()}.

start_pool(Name, Opts)

-spec start_pool(kura_pool:name(), kura_pool:opts()) -> {ok, pid()} | {error, term()}.

stop_pool(Name)

-spec stop_pool(kura_pool:name()) -> ok.