Overview
Description
This category provides a set of extensions for typed features. Instead of column strings, typed methods take a KeyProxyCallback like user => user.name, so column names are checked by TypeScript.
Where methods also go into JSON columns (exec => exec.details.meta.endTs, see Paths into JSON columns), and with the opt-in strictParams their parameters are checked against the column type.
Methods:
- typed: set the root of the typed callbacks once for the query, e.g. its aliases.
from()andaddFrom()keep it. - selectTyped: add typesafe select to a query.
- selectRow / unnestRows: the body of a CTE or subquery, checked against the row type of the
tableHelperthat reads it. - joinTyped: add typesafe join to a query, and map joined data to a typed property (
leftJoinAndMapOneTyped,leftJoinAndMapManyTyped, …). - whereTyped: add typesafe condition to a query.
- whereIsInTyped: add typesafe IN / NOT IN condition to a query.
- whereIsAnyTyped: add typesafe
= ANY(array)condition to a query (only PostgreSQL). - whereArrayContainsTyped / ContainedByTyped / OverlapsTyped: add typesafe array column conditions to a query (only PostgreSQL).
- whereJsonContainsTyped / whereJsonHasKeyTyped: add typesafe JSON column conditions to a query (only PostgreSQL).
- whereIsDistinctFromTyped: add typesafe null-safe comparison to a query.
- applyPeriodFilterTyped: filter by a period of a typesafe date / time property.
- whereILikeTyped: add typesafe case-insensitive
LIKEwith escaped wildcards (ILIKEon PostgreSQL). - whereSearchTyped: search several columns for one value, as one
ORgroup. - whereLowerEqualsTyped / whereIsInLowerTyped: add typesafe case-insensitive equality /
IN(LOWER(…)). - whereSimilarTyped / addSimilarityScoreTyped: add typesafe trigram similarity conditions and scores (PostgreSQL +
pg_trgm). - orderByTyped: add typesafe order to a query.
- distinctOnTyped: add typesafe distinct on to a query (only PostgreSQL).
- groupByTyped: add typesafe GROUP BY to a query.
- havingTyped: add a typesafe HAVING condition on an aggregate (
COUNT,SUM,MAX, …) of a property. - orderByArrayPositionTyped: order by the position of a property's value in an array (only PostgreSQL).
- orderBySimilarityTyped: order by trigram similarity to a term, NULLs last, or by distance through a GiST index (PostgreSQL +
pg_trgm). - addSelectCalculatedTyped: select into a
@CalculatedColumnpicked by a typed callback;orderByTyped/addOrderByTypedthen order by it. - returningTyped: return typesafe columns from INSERT / UPDATE / DELETE (PostgreSQL, MariaDB, SQL Server).
- onConflictTyped:
ON CONFLICT … DO UPDATE/DO NOTHINGwith typesafe columns (PostgreSQL, SQLite). - valuesFromSelectTyped:
INSERT INTO … (columns) SELECT …, the rows of an insert from a select query.
Types:
- KeyProxyCallback: the callback that selects entity properties, and how it maps to SQL keys.
- Json<T>: marks a JSON column, so typed callbacks go into it at any depth.