Skip to content

Commit 3a9d03f

Browse files
committedSep 28, 2023
improve select function calls example even more
1 parent d8bc552 commit 3a9d03f

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed
 

‎site/docs/examples/SELECT/0060-function-calls.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,31 @@ const result = await db.selectFrom('person')
99
// functions.
1010
fn.count<number>('pet.id').as('pet_count'),
1111
12-
// You can call any function by calling \`fn\` directly.
13-
// The arguments are treated as column references by
14-
// default. If you want to pass in values, use the
15-
// \`val\` function.
16-
fn<string>('concat', [val('Ms. '), 'first_name', 'last_name']).as('full_name_with_title'),
12+
// You can call any function by calling \`fn\`
13+
// directly. The arguments are treated as column
14+
// references by default. If you want to pass in
15+
// values, use the \`val\` function.
16+
fn<string>('concat', [
17+
val('Ms. '),
18+
'first_name',
19+
val(' '),
20+
'last_name'
21+
]).as('full_name_with_title'),
1722
1823
// You can call any aggregate function using the
1924
// \`fn.agg\` function.
2025
fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names'),
2126
22-
// And once again, you can use the \`sql\` template tag.
23-
// The template tag substitutions are treated as values
24-
// by default. If you want to reference columns, you can
25-
// use the \`ref\` function.
26-
sql<string>\`concat(\${ref('first_name')}, \${ref('last_name')})\`.as('full_name')
27+
// And once again, you can use the \`sql\`
28+
// template tag. The template tag substitutions
29+
// are treated as values by default. If you want
30+
// to reference columns, you can use the \`ref\`
31+
// function.
32+
sql<string>\`concat(
33+
\${ref('first_name')},
34+
' ',
35+
\${ref('last_name')}
36+
)\`.as('full_name')
2737
])
2838
.groupBy('person.id')
2939
.having((eb) => eb.fn.count('pet.id'), '>', 10)

‎src/query-builder/function-module.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,31 @@ import { Selectable } from '../util/column-type.js'
4545
* // functions.
4646
* fn.count<number>('pet.id').as('pet_count'),
4747
*
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'),
48+
* // You can call any function by calling `fn`
49+
* // directly. The arguments are treated as column
50+
* // references by default. If you want to pass in
51+
* // values, use the `val` function.
52+
* fn<string>('concat', [
53+
* val('Ms. '),
54+
* 'first_name',
55+
* val(' '),
56+
* 'last_name'
57+
* ]).as('full_name_with_title'),
5358
*
5459
* // You can call any aggregate function using the
5560
* // `fn.agg` function.
5661
* fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names'),
5762
*
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')
63+
* // And once again, you can use the `sql`
64+
* // template tag. The template tag substitutions
65+
* // are treated as values by default. If you want
66+
* // to reference columns, you can use the `ref`
67+
* // function.
68+
* sql<string>`concat(
69+
* ${ref('first_name')},
70+
* ' ',
71+
* ${ref('last_name')}
72+
* )`.as('full_name')
6373
* ])
6474
* .groupBy('person.id')
6575
* .having((eb) => eb.fn.count('pet.id'), '>', 10)
@@ -72,13 +82,13 @@ import { Selectable } from '../util/column-type.js'
7282
* select
7383
* "person"."id",
7484
* count("pet"."id") as "pet_count",
75-
* concat($1, "first_name", "last_name") as "full_name_with_title",
85+
* concat($1, "first_name", $2, "last_name") as "full_name_with_title",
7686
* array_agg("pet"."name") as "pet_names",
77-
* concat("first_name", "last_name") as "full_name"
87+
* concat("first_name", ' ', "last_name") as "full_name"
7888
* from "person"
7989
* inner join "pet" on "pet"."owner_id" = "person"."id"
8090
* group by "person"."id"
81-
* having count("pet"."id") > $2
91+
* having count("pet"."id") > $3
8292
* ```
8393
*/
8494
export interface FunctionModule<DB, TB extends keyof DB> {

1 commit comments

Comments
 (1)

vercel[bot] commented on Sep 28, 2023

@vercel[bot]

Successfully deployed to the following URLs:

kysely – ./

kysely-git-master-kysely-team.vercel.app
kysely.dev
kysely-kysely-team.vercel.app
www.kysely.dev

Please sign in to comment.