Delete
DELETE statements with where clauses and returning
Delete works exactly the same as insert and updated but there is no set clause since no values are being set.
val joeId = 123
val q =
sql {
delete<Person>.where { id == param(joeId) }
}
q.buildFor.Postgres().runOn(myDatabase)
//> DELETE FROM Person WHERE id = ?
Delete with Returning
The Delete DSL also supports returning clauses:
val joeId = 123
val q =
sql {
delete<Person>
.where { id == param(joeId) }
.returning { p -> p.id }
}
q.buildFor.Postgres().runOn(myDatabase) // Also works with SQLite
//> DELETE FROM Person WHERE id = ? RETURNING id
q.buildFor.SqlServer().runOn(myDatabase)
//> DELETE FROM Person OUTPUT DELETED.id WHERE id = ?