@@ -34,18 +34,32 @@ import { Selectable } from '../util/column-type.js'
3434 * This example uses the `fn` module to select some aggregates:
3535 *
3636 * ```ts
37+ * import { sql } from 'kysely'
38+ *
3739 * const result = await db.selectFrom('person')
3840 * .innerJoin('pet', 'pet.owner_id', 'person.id')
39- * .select(({ fn }) => [
41+ * .select(({ fn, val, ref }) => [
4042 * 'person.id',
4143 *
4244 * // The `fn` module contains the most common
4345 * // functions.
4446 * fn.count<number>('pet.id').as('pet_count'),
4547 *
46- * // You can call any function using the
47- * // `agg` method
48- * fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names')
48+ * // You can call any function by calling `fn` directly.
49+ * // The arguments are treated as column references by
50+ * // default. If you want to pass in values, use the
51+ * // `val` function.
52+ * fn<string>('concat', [val('Ms. '), 'first_name', 'last_name']).as('full_name_with_title'),
53+ *
54+ * // You can call any aggregate function using the
55+ * // `fn.agg` function.
56+ * fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names'),
57+ *
58+ * // And once again, you can use the `sql` template tag.
59+ * // The template tag substitutions are treated as values
60+ * // by default. If you want to reference columns, you can
61+ * // use the `ref` function.
62+ * sql<string>`concat(${ref('first_name')}, ${ref('last_name')})`.as('full_name')
4963 * ])
5064 * .groupBy('person.id')
5165 * .having((eb) => eb.fn.count('pet.id'), '>', 10)
@@ -58,11 +72,13 @@ import { Selectable } from '../util/column-type.js'
5872 * select
5973 * "person"."id",
6074 * count("pet"."id") as "pet_count",
61- * array_agg("pet"."name") as "pet_names"
75+ * concat($1, "first_name", "last_name") as "full_name_with_title",
76+ * array_agg("pet"."name") as "pet_names",
77+ * concat("first_name", "last_name") as "full_name"
6278 * from "person"
6379 * inner join "pet" on "pet"."owner_id" = "person"."id"
6480 * group by "person"."id"
65- * having count("pet"."id") > $1
81+ * having count("pet"."id") > $2
6682 * ```
6783 */
6884export interface FunctionModule < DB , TB extends keyof DB > {
0 commit comments