Skip to content

Commit

Permalink
fix jsdocs @ output-interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Nov 23, 2024
1 parent 1537494 commit cd51c1f
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions src/query-builder/output-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ export interface OutputInterface<
* .output('inserted.id')
* .values({
* first_name: 'Jennifer',
* last_name: 'Aniston'
* last_name: 'Aniston',
* gender: 'female',
* })
* .executeTakeFirst()
* .executeTakeFirstOrThrow()
* ```
*
* The generated SQL (MSSQL):
*
* ```sql
* insert into "person" ("first_name", "last_name", "gender")
* output "inserted"."id"
* values (@1, @2, @3)
* ```
*
* Return multiple columns:
*
* ```ts
* const { id, first_name } = await db
* const { old_first_name, old_last_name, new_first_name, new_last_name } = await db
* .updateTable('person')
* .set({ first_name: 'John', last_name: 'Doe' })
* .output([
Expand All @@ -48,21 +57,41 @@ export interface OutputInterface<
* 'inserted.last_name as new_last_name',
* ])
* .where('created_at', '<', new Date())
* .executeTakeFirst()
* .executeTakeFirstOrThrow()
* ```
*
* The generated SQL (MSSQL):
*
* ```sql
* update "person"
* set "first_name" = @1, "last_name" = @2
* output "deleted"."first_name" as "old_first_name",
* "deleted"."last_name" as "old_last_name",
* "inserted"."first_name" as "new_first_name",
* "inserted"."last_name" as "new_last_name"
* where "created_at" < @3
* ```
*
* Return arbitrary expressions:
*
* ```ts
* import { sql } from 'kysely'
*
* const { id, full_name } = await db
* const { full_name } = await db
* .deleteFrom('person')
* .output((eb) => sql<string>`concat(${eb.ref('deleted.first_name')}, ' ', ${eb.ref('deleted.last_name')})`.as('full_name'))
* .where('created_at', '<', new Date())
* .executeTakeFirstOrThrow()
* ```
*
* The generated SQL (MSSQL):
*
* ```sql
* delete from "person"
* output concat("deleted"."first_name", ' ', "deleted"."last_name") as "full_name"
* where "created_at" < @1
* ```
*
* Return the action performed on the row:
*
* ```ts
Expand All @@ -81,7 +110,21 @@ export interface OutputInterface<
* 'inserted.id as inserted_id',
* 'deleted.id as deleted_id',
* ])
* .execute()
* ```
*
* The generated SQL (MSSQL):
*
* ```sql
* merge into "person"
* using "pet" on "pet"."owner_id" = "person"."id"
* when matched then delete
* when not matched then
* insert ("first_name", "last_name", "gender")
* values (@1, @2, @3)
* output "inserted"."id" as "inserted_id", "deleted"."id" as "deleted_id"
* ```
*
*/
output<OE extends OutputExpression<DB, TB, OP>>(
selections: ReadonlyArray<OE>,
Expand Down

0 comments on commit cd51c1f

Please sign in to comment.