import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { DeleteQueryBuilder } = kysely;
Adds returning *
or returning table.*
clause to the query.
Examples
Return all columns.
const pets = await db
.deleteFrom('pet')
.returningAll()
.execute()
The generated SQL (PostgreSQL)
delete from "pet" returning *
Return all columns from all tables
const result = ctx.db
.deleteFrom('toy')
.using(['pet', 'person'])
.whereRef('toy.pet_id', '=', 'pet.id')
.whereRef('pet.owner_id', '=', 'person.id')
.where('person.first_name', '=', 'Zoro')
.returningAll()
.execute()
The generated SQL (PostgreSQL)
delete from "toy"
using "pet", "person"
where "toy"."pet_id" = "pet"."id"
and "pet"."owner_id" = "person"."id"
and "person"."first_name" = $1
returning *
Return all columns from a single table.
const result = ctx.db
.deleteFrom('toy')
.using(['pet', 'person'])
.whereRef('toy.pet_id', '=', 'pet.id')
.whereRef('pet.owner_id', '=', 'person.id')
.where('person.first_name', '=', 'Itachi')
.returningAll('pet')
.execute()
The generated SQL (PostgreSQL)
delete from "toy"
using "pet", "person"
where "toy"."pet_id" = "pet"."id"
and "pet"."owner_id" = "person"."id"
and "person"."first_name" = $1
returning "pet".*
Return all columns from multiple tables.
const result = ctx.db
.deleteFrom('toy')
.using(['pet', 'person'])
.whereRef('toy.pet_id', '=', 'pet.id')
.whereRef('pet.owner_id', '=', 'person.id')
.where('person.first_name', '=', 'Luffy')
.returningAll(['toy', 'pet'])
.execute()
The generated SQL (PostgreSQL)
delete from "toy"
using "pet", "person"
where "toy"."pet_id" = "pet"."id"
and "pet"."owner_id" = "person"."id"
and "person"."first_name" = $1
returning "toy".*, "pet".*
Parameters
tables: ReadonlyArray<T>
Returns
DeleteQueryBuilder<DB, TB, ReturningAllRow<DB, T, O>>
Adds a returning *
to an insert/update/delete query on databases
that support returning
such as PostgreSQL.
Parameters
table: T
Returns
DeleteQueryBuilder<DB, TB, ReturningAllRow<DB, T, O>>
Returns
DeleteQueryBuilder<DB, TB, ReturningAllRow<DB, TB, O>>