Closes the pool via close, so await using releases it on scope
exit, including when an exception unwinds the scope.
Run one statement on any available connection and return every row.
The complete result is materialized natively before JavaScript objects are created on the event-loop thread, so a large result has a high peak memory footprint and its conversion can still pause JavaScript.
Exactly one executable SQL statement.
Optionalparams: PoolParamsRun several operations sequentially on one leased connection, in one worker
job. All SQL and parameters must be known when batch() is called.
Use this when operations must share a connection or a transaction. Separate calls may be leased to different connections and complete in any order.
Descriptors to run, whose results are returned in order.
Optionaloptions: PoolBatchOptions
Set transaction for all-or-nothing semantics.
const results = await pool.batch(
[
{ kind: "run", sql: "UPDATE account SET balance = balance - ? WHERE id = ?", params: [10, 1] },
{ kind: "run", sql: "UPDATE account SET balance = balance + ? WHERE id = ?", params: [10, 2] },
{ kind: "get", sql: "SELECT balance FROM account WHERE id = ?", params: [2] },
],
{ transaction: "immediate" },
);
Close the pool. Closing begins immediately: new work is rejected, work already accepted drains, and then each physical connection closes exactly once.
Idempotent; concurrent and repeated callers share one outcome.
Resolves once every connection has closed.
Run one statement on any available connection and return its first row.
The statement still runs to completion, so INSERT ... RETURNING applies
all of its changes even though only the first row is returned.
Exactly one executable SQL statement.
Optionalparams: PoolParamsThe first row, or undefined when the statement produced none.
Run one statement on any available connection and discard its rows.
Exactly one executable SQL statement.
Optionalparams: PoolParamsThe number of rows the statement changed. There is no
lastInsertRowid; use INSERT ... RETURNING with get or
all when generated values matter.
StaticopenOpen every connection in the pool, run DatabasePoolOptions.connectionSetup on each, and resolve once all of them are ready.
Database path, :memory:, or a SQLite URI. Buffer and
URL locations are copied before the asynchronous open begins.
Optionaloptions: DatabasePoolOptions
Pool configuration. Unknown keys are rejected.
A pool ready to accept operations.
An experimental fixed-size pool of warm SQLite connections.
SQL execution and connection lifecycle work run on libuv worker threads. Calls waiting for a connection stay in the JavaScript scheduler and consume no libuv worker.
This API is experimental. Its compatibility policy is separate from the stable
@photostructure/sqliteentry point, and it may change as production usage and benchmarks reveal better semantics.Only connection-independent operations are exposed. Prepared-statement handles, iteration, streaming, JavaScript transaction callbacks, user functions, sessions, changesets, backup, and serialization are deliberately omitted; use
DatabaseSyncfor workloads needing that stateful surface.Example
See
Experimental async database pool for ordering, concurrency, libuv sizing, and closing semantics.