Skip to content

Commit

Permalink
improve select function calls example even more
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Sep 28, 2023
1 parent d8bc552 commit 6790982
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
28 changes: 18 additions & 10 deletions site/docs/examples/SELECT/0060-function-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,29 @@ const result = await db.selectFrom('person')
// functions.
fn.count<number>('pet.id').as('pet_count'),
// You can call any function by calling \`fn\` directly.
// The arguments are treated as column references by
// default. If you want to pass in values, use the
// \`val\` function.
fn<string>('concat', [val('Ms. '), 'first_name', 'last_name']).as('full_name_with_title'),
// You can call any function by calling \`fn\`
// directly. The arguments are treated as column
// references by default. If you want to pass in
// values, use the \`val\` function.
fn<string>('concat', [
val('Ms. '),
'first_name',
'last_name'
]).as('full_name_with_title'),
// You can call any aggregate function using the
// \`fn.agg\` function.
fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names'),
// And once again, you can use the \`sql\` template tag.
// The template tag substitutions are treated as values
// by default. If you want to reference columns, you can
// use the \`ref\` function.
sql<string>\`concat(\${ref('first_name')}, \${ref('last_name')})\`.as('full_name')
// And once again, you can use the \`sql\`
// template tag. The template tag substitutions
// are treated as values by default. If you want
// to reference columns, you can use the \`ref\`
// function.
sql<string>\`concat(
\${ref('first_name')},
\${ref('last_name')}
)\`.as('full_name')
])
.groupBy('person.id')
.having((eb) => eb.fn.count('pet.id'), '>', 10)
Expand Down
28 changes: 18 additions & 10 deletions src/query-builder/function-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,29 @@ import { Selectable } from '../util/column-type.js'
* // functions.
* fn.count<number>('pet.id').as('pet_count'),
*
* // You can call any function by calling `fn` directly.
* // The arguments are treated as column references by
* // default. If you want to pass in values, use the
* // `val` function.
* fn<string>('concat', [val('Ms. '), 'first_name', 'last_name']).as('full_name_with_title'),
* // You can call any function by calling `fn`
* // directly. The arguments are treated as column
* // references by default. If you want to pass in
* // values, use the `val` function.
* fn<string>('concat', [
* val('Ms. '),
* 'first_name',
* 'last_name'
* ]).as('full_name_with_title'),
*
* // You can call any aggregate function using the
* // `fn.agg` function.
* fn.agg<string[]>('array_agg', ['pet.name']).as('pet_names'),
*
* // And once again, you can use the `sql` template tag.
* // The template tag substitutions are treated as values
* // by default. If you want to reference columns, you can
* // use the `ref` function.
* sql<string>`concat(${ref('first_name')}, ${ref('last_name')})`.as('full_name')
* // And once again, you can use the `sql`
* // template tag. The template tag substitutions
* // are treated as values by default. If you want
* // to reference columns, you can use the `ref`
* // function.
* sql<string>`concat(
* ${ref('first_name')},
* ${ref('last_name')}
* )`.as('full_name')
* ])
* .groupBy('person.id')
* .having((eb) => eb.fn.count('pet.id'), '>', 10)
Expand Down

1 comment on commit 6790982

@vercel
Copy link

@vercel vercel bot commented on 6790982 Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kysely – ./

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

Please sign in to comment.