Upgrading from 2.x
3.0 keeps the 2.x API: every export of 2.1.0 is still there except the ones removed below. Most code upgrades by bumping the version. TypeScript points at everything in the first part; the second part compiles as before and needs a search of your code.
What TypeScript flags
| 2.x | 3.0 |
|---|---|
query.applyPaginationFilter(filter) | query.applyPagination(filter): the same arguments and result |
t.jsonColumn('metadata', '->>', 'role') | t.jsonText((r) => r.metadata.role) |
t.jsonColumn('metadata', '->', 'settings'), t.jsonPath(…) | t.json((r) => r.metadata.settings) |
returningTyped((t) => [t.id, t.status]) | returningTyped((t) => ({ id: t.id, status: t.status })) |
the JsonFieldRest type | removed: only jsonColumn / jsonPath used it |
WhereInMethods / WhereAnyMethods | still there, deprecated: WhereIsInMethodName / WhereIsAnyMethodName |
Code that builds a ListWithTotals or a ListWithCursor itself, such as a test mock or a wrapper, adds hasMore and pageSize, and page for ListWithTotals. Code that only reads them needs no change.
What to check in your code
- Rows from
returningTyped. The rows inexecute()'sraware keyed by the output names you give, not by the database column names, and hold only those outputs: an INSERT no longer adds its generated columns. Look at the code that readsrawafter areturningTyped. - Typed keys of an alias without an entity.
selectTyped,orderByTyped,groupByTypedanddistinctOnTypednow quote the keys of a subquery, a CTE or a table that isn't an entity, as the typed where methods already did. A column that raw SQL names without quotes (SELECT id AS userId) isuseridon PostgreSQL, socte.userIdno longer matches it: quote the name in the SQL,AS "userId". - Cursors issued by 2.x. Cursors now name the direction of their keys. A descending cursor from 2.x gets an
InvalidCursorErroronce; ascending cursors keep working. If clients hold cursors across your deploy, answer that error by starting the list again from its first page. - Inputs that now throw a
TypeError. 2.x dropped them or read them as something else:- a params object after the condition with more than one key, or none:
whereTyped((u) => u.id, '=', { id, email }); applyOrder/applyOrderFilterwithuseQuotes: falseand an expression in place of a column name;- an order without a
field; whereIsIn/whereIsAny/innerJoinUnnestgiven a value that is neither a list nor one value, such as the object a query string makes of a long list;whereArrayContains,whereArrayContainedByandwhereArrayOverlapson a database other than PostgreSQL: MySQL read&&as a logical AND and returned the wrong rows.whereSimilarTyped(andand…/or…) andaddSimilarityScoreTypedon a database other than PostgreSQL: there%is the modulo operator, so the query ran and matched no row. They throw even for a blank term.whereSearchTypedwithout the newsimilaroption works on every database as before.
- a params object after the condition with more than one key, or none:
- Pool connections. Without a query runner of its own,
getManyWithTotalsruns the count and the page at the same time and holds two pool connections for the call, where 2.x held one. Size the pool for it, or passdisableTotalsCalculationwhere a list needs no total.
No action needed
Most entries under Bug Fixes in the changelog turn SQL the database rejected into SQL that runs, or into a TypeError that names the call. Code that worked needs no change for them.