Skip to content

feat(experimental): add async DatabasePool subpath - #102

Open
mceachen wants to merge 3 commits into
mainfrom
feat/experimental-async-database-pool
Open

feat(experimental): add async DatabasePool subpath#102
mceachen wants to merge 3 commits into
mainfrom
feat/experimental-async-database-pool

Conversation

@mceachen

@mceachen mceachen commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

  • Add a fixed-size DatabasePool at @photostructure/sqlite/experimental.
  • Run SQLite open, prepare, bind, step, finalize, setup, and close work on libuv workers.
  • Keep the stable root API unchanged.
  • Default to a strict authorizer that rejects connection-affine SQL.
  • Include API documentation, a reproducible benchmark runner and summary, package-export checks, and native memory tooling.

API and behavior

The pool exposes asynchronous run, get, all, and explicit batch operations over warm connections. Declarative connection setup supports PRAGMAs, attachments, and temporary extension loading before a connection enters the pool.

The API deliberately omits connection and statement handles, JavaScript SQLite callbacks, streaming, and transaction callbacks. Transactional work is submitted as one explicit batch, so each job remains valid on any leased connection.

See the experimental API guide and archived technical project plan.

Performance

A documented local reference run recorded multiple operations per millisecond from warm connections and substantial scaling from additional libuv capacity under competing worker-pool load. Generated raw reports remain local and are not versioned. The measurements are evidence, not functional-test timing assertions.

Validation

Post-rebase checks:

  • Clean native rebuild and distribution build
  • TypeScript and ESLint
  • CJS: 73 suites and 1,072 tests passed
  • Async pool: 8 suites and 101 tests passed
  • CJS, ESM, and TypeScript package-export checks
  • Focused pool lifecycle passed under ASan/UBSan

The archived plan records the earlier full ESM, unsuppressed LSan, Valgrind, and Alpine Node 22/24/26 runs. In the current sandbox, leak-at-exit checking is blocked by ptrace policy. The current full ESM run also reaches one pre-existing mainline failure in test/release-load.test.ts because it uses __dirname; this branch does not modify that file.

Expose a fixed-size pool of warm SQLite connections at
@photostructure/sqlite/experimental so SQL executes on libuv workers
instead of the event loop; the stable root surface is unchanged. Warm
connections meet the multi-op/ms target that per-operation opens miss,
and the default strict authorizer rejects connection-affine SQL so
calls stay correct on any leased connection. See the archived TPP in
doc/done/ for the contract and validation evidence.
Comment thread src/async_pool_impl.cpp
}
if (value.IsNumber()) {
const double number = value.As<Napi::Number>().DoubleValue();
if (std::isfinite(number) && std::trunc(number) == number &&
Comment thread src/async_pool_impl.cpp
Comment on lines +906 to +909
if (!response_.error.present &&
!RunSetup(db, state().get(), configuration_.setup, &response_.error)) {
// Error is already captured.
}
Comment thread src/async_pool_impl.cpp
return true;
}

int BindValue(sqlite3_stmt *statement, int index, const NativeValue &value) {
Remove machine-specific raw reports from version control while retaining
reproducible commands and summarized evidence.
Avoid deployment-gated variant access and initialize Node-API handles so platform compilers can prove the native paths are safe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants