컨텐츠로 건너뛰기

Kysely Delete

이 내용은 아직 번역본이 없습니다.

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