Repository navigation
sql-storage-adapter v0.6.15
·
366 commits
to master
since this release
Added
- Pool control on the PostgreSQL adapter.
withConnection(fn)holds one pooled connection forfn, for session settings, session advisory locks, temporary tables and statements outside a transaction. It returns the connection to the pool whenfnresolves. It closes the connection whenfnthrows (rethrowingfn's error) or returns inside a transaction it began (rejecting; pg 8.21 and later report the status). The connection refuses statements afterfnends.getPoolStats()returns{ total, idle, waiting }, ornullwhen the adapter is not open.transaction(fn, { isolationLevel, readOnly, deferrable })sets how the transaction begins, on the adapter and on a held connection, and refuses an unknown isolation level before any SQL is sent. TheallowExitOnIdleoption passes pg's option to the pool, so Node can exit while the pool is idle. The types arePostgresConnection,PostgresPoolStats,PostgresTransactionOptionsandPostgresIsolationLevel. strictoncreateDatabase()andresolveStorageAdapter(), for servers: only the database the options name opens. A postgres candidate that fails ends resolution with aStorageResolutionErrorwhosecauseshold its error, whateverprioritylists after it; withoutstrictit falls through to better-sqlite3, IndexedDB and sql.js. WithDATABASE_URLor Postgres options that name a server and nopriority,['postgres']is the whole list. An explicit file path outranksDATABASE_URL, which is then not read. Aurlorpostgresoption that names no server ({ url: process.env.DATABASE_URL }with the variable unset), or Postgres options given to the resolver with noDATABASE_URLto fill them in, fails instead of opening the local default, unless a file is given.strictis off by default, and resolution without it is unchanged.
Changed
- CI runs the PostgreSQL integration suite (17 tests) and the dialect and full-text search suite (9 tests) against its PostgreSQL 16 service; both skipped in CI before. They read
POSTGRES_TEST_URL, as thecreateDatabasespecs do: the integration suite readTEST_POSTGRES_URL, which it still reads whenPOSTGRES_TEST_URLis unset, and the dialect suite readDATABASE_URL, which also moves the resolver's default to Postgres. The integration suite fails when its server cannot be reached, where its tests returned early and passed, and its granular-configuration test takes the host, port, database, user and password from the URL.
Fixed
- PostgreSQL
transaction(): when the connection broke and ROLLBACK failed too, the ROLLBACK error replaced the transaction's own error. A caller looking for a unique violation, or its own exception, saw "Client has encountered a connection error and is not queryable" instead. The transaction's own error (the callback's, or COMMIT's) is thrown now, with the ROLLBACK error on it as a non-enumerablerollbackErrorproperty, and the adapter logs one warning. The broken connection is closed instead of returned to the pool. It was released as healthy. - PostgreSQL
transaction()andwithConnection(): a connection the server closed while a callback held it, between statements, ended the process. pg emits that error on the client when no query is running, and pg-pool listens only on idle clients. Examples areidle_in_transaction_session_timeout, a failover and an administrator'spg_terminate_backend. A checked-out connection now has a listener; the error closes the connection when it is released, and the pool opens a new one. A BEGIN that fails closes the connection too. - PostgreSQL: a transaction's handle used after its transaction ended ran its statements on the pooled connection it had held. When another caller held that connection inside a transaction, the statements ran in that caller's transaction and were undone by its rollback, after the handle's caller had been told they succeeded. Once its transaction has ended, the handle now runs on the pool, as the adapter's own statements do. Its
transaction()begins a new transaction; before, it ran the callback with no transaction at all. This matches better-sqlite3, where a handle used after its transaction waits like any other caller. - The
createDatabase()documentation and the remote-connection guide said thatcreateDatabase()with no options opens PostgreSQL whenDATABASE_URLis set. It opens the local default; passurl: process.env.DATABASE_URL. The README's cloud example passedpostgres: { connectionString: process.env.DATABASE_URL }, which opens a local SQLite file when the variable is unset; it passesurlwithstrictnow. - The README showed
createDatabase()takingperformanceandhooksoptions.DatabaseOptionshas neither, and no adapter applies a tier or runs hooks: the README now shows the exportedresolvePerformanceConfig()andcombineHooks()instead, and the optimization guide says so at its top.