Skip to content

Kysely Delete

This content is not available in your language yet.

Short and simple examples of how to write delete queries.

Single row

Schema

import { Generated } from 'kysely'
declare global {
interface DB {
person: PersonTable
pet: PetTable
}
interface PersonTable {
id: Generated<string>
first_name: string
last_name: string | null
created_at: Generated<Date>
age: number
}
interface PetTable {
id: Generated<string>
name: string
owner_id: string
species: 'cat' | 'dog'
is_favorite: boolean
}
}

Querying

const result = await db
.deleteFrom('person')
.where('person.id', '=', '1')
.executeTakeFirst()
console.log(result.numDeletedRows)

Result

DELETE FROM "person"
WHERE
"person"."id" = $1
-- Parameters
-- [1] 1