The typed query builder (commons data 0053-sql-typed): from(table) and joins build a scope of typed columns, keyed by the names of the tables in the query; a join gives its table's columns as they are, or nullable where an outer join may leave them out; select names what is wanted and gives the type of a row; the clauses (where, group by, having, order by, limit, offset, distinct), set operations, subqueries and common table expressions follow. A query is data; toSql writes it for a dialect and run runs it through a driver.
<N extends string, R, I, Out extends Scope>(kind: "CROSS" | "FULL" | "INNER" | "LEFT" | "RIGHT", table: Table<R, I, N>, on: ((s: never) => Expr<boolean>) | undefined, widen: Record<string, unknown>) => From<Out>
innerJoin
<N extends string, R, I>(table: Table<R, I, N extends keyof S ? never : N>, on: (s: S & { readonly [A in N]: Columns<R>; }) => Expr<boolean>) => From<S & { readonly [A in N]: Columns<R>; }>
INNER JOIN: the rows that have a partner.
leftJoin
<N extends string, R, I>(table: Table<R, I, N extends keyof S ? never : N>, on: (s: S & { readonly [A in N]: Columns<R>; }) => Expr<boolean>) => From<S & { readonly [A in N]: NullableColumns<R>; }>
LEFT JOIN: every row, and the columns of the table are null where there is no partner.
rightJoin
<N extends string, R, I>(table: Table<R, I, N extends keyof S ? never : N>, on: (s: S & { readonly [A in N]: Columns<R>; }) => Expr<boolean>) => From<NullAll<S> & { readonly [A in N]: Columns<R>; }>
RIGHT JOIN: every row of the table, and the columns of the tables before are null where there is no partner.
fullJoin
<N extends string, R, I>(table: Table<R, I, N extends keyof S ? never : N>, on: (s: S & { readonly [A in N]: Columns<R>; }) => Expr<boolean>) => From<NullAll<S> & { readonly [A in N]: NullableColumns<R>; }>
FULL JOIN: every row of both; the columns of either are null where there is no partner.
crossJoin
<N extends string, R, I>(table: Table<R, I, N extends keyof S ? never : N>) => From<S & { readonly [A in N]: Columns<R>; }>
CROSS JOIN: every row with every row.
where
(condition: (s: S) => Expr<boolean>) => From<S>
A condition on the rows; more than one is all of them.