Repository navigation
fix: reuse connections after result errors and fix oneFirst, routed retry limit, 22P02 cause and docs - #829
Merged
Merged
Conversation
…etry limit, 22P02 cause and docs
🦋 Changeset detectedLatest commit: 622ae06 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
gajus
commented
Nov 5, 2026
|
|
||
| This function can optionally return a direct result of the query which will cause the actual query never to be executed. | ||
|
|
||
| Note: Not executed for queries executed using `stream`. |
Owner
Author
There was a problem hiding this comment.
use special blockquotes for all notes, e.g.
Note
Useful information that users should know, even when skimming content.
Update all similar notes in README to use the same format instead of plain note:
gajus
commented
Nov 5, 2026
| "slonik": minor | ||
| --- | ||
|
|
||
| fix: `pool.transaction(handler, transactionRetryLimit)` passes `transactionRetryLimit` to the pool returned by a `beforePoolConnection` interceptor. |
Owner
Author
There was a problem hiding this comment.
Avoid literal configuration values. Pass instead {retryLimit?: number} object.
Merged
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a set of inconsistencies between the API, its implementation and the documentation.
Reuse connections after result errors
A query that failed with
NotFoundError,DataIntegrityErrororSchemaValidationErrordestroyed its connection, e.g. everypool.one()that found no rows. These errors describe the result of a query that succeeded, so the connection is healthy: it is now returned to the pool. This applies to queries and transactions on the pool. A routine passed topool.connect()can leave the connection in any state, so its connection is still destroyed when the routine fails.oneFirstthrowsDataIntegrityErrorfor multiple columnsoneFirstthrewUnexpectedStateErrorwhen the query returned multiple columns (it passed its column check toone(), which ignored it). It now throwsDataIntegrityError("Query returned rows with multiple columns."), as documented, and likemaybeOneFirst,anyFirstandmanyFirst. The error also goes through thedataIntegrityErrorinterceptor now.Remove the
valuesparameter from the query method typesThe query methods accepted a second
valuesparameter, which was ignored. It is removed from the types. TypeScript code that passed it no longer compiles; this is marked asminor, because the values were never used.retryLimitoption oftransaction()transaction()accepts options instead of a number, e.g.pool.transaction(handler, { retryLimit: 3 }). Passing the retry limit as the second argument (pool.transaction(handler, 3)) still works, but is deprecated. The newTransactionOptionstype is exported.pool.transaction()used to drop the retry limit when abeforePoolConnectioninterceptor returned another pool; the options are now passed to that pool.Errors of row transformers in
stream()When a
transformRowortransformRowAsyncinterceptor threw duringstream()(e.g. a result parser that throwsSchemaValidationError), the error became an unhandled rejection (which crashes the process by default),stream()never settled, and the connection was never released. Now:stream()rejects with the error.stream()waits for the promise returned by the stream handler, e.g. anasyncfunction that usesfor await, which rejects when the stream fails.pipedoes not propagate destruction), and every subsequent query of the connection waited behind it, e.g. theROLLBACKof the surrounding transaction.Keep the original error of 22P02
InvalidInputErrorraised for SQLSTATE 22P02 (invalid text representation) now includes the original error ascause, like the other errors that the driver maps.Documentation
sqltag functions throwingInvalidInputErrorwhen they are not called as tagged template literals.t1.transactioninside oft2, which throws "Cannot run a query using parent transaction."; it now callst2.transaction.errorevent is emitted when a query fails with aSlonikError, not for all errors.afterQueryExecution,beforeQueryExecutionandbeforeQueryResultare not executed for queries executed usingstream.> [!NOTE]blocks.Tests
NotFoundError,DataIntegrityErrorandSchemaValidationError(implicit queries and transactions), and not re-used after a failedpool.connect()routine.oneFirstthrowsDataIntegrityErrorfor multiple columns.retryLimitoption limits the retries of transactions and nested transactions; so does the deprecated retry limit argument.InvalidInputErrorhas the original error ascause.stream()rejects with the error of atransformRow/transformRowAsyncinterceptor (using adatalistener andfor await), after which the connection is re-used; a transaction in which a stream failed is rolled back; a connection can run queries after a stream failed.