check(_:)
Adds a check constraint.
This declaration is deprecated.
func check(_ condition: some SQLExpressible)
Parameters
- condition
The checked condition.
For example:
// CREATE TABLE player (
// personalPhone TEXT,
// workPhone TEXT,
// CHECK personalPhone IS NOT NULL OR workPhone IS NOT NULL
// )
try db.create(table: "player") { t in
t.column("personalPhone", .text)
t.column("workPhone", .text)
let personalPhone = Column("personalPhone")
let workPhone = Column("workPhone")
t.check(personalPhone != nil || workPhone != nil)
}
When defining a check constraint on a single column, you can use the check(_:)
shortcut:
// CREATE TABLE player(
// name TEXT CHECK (LENGTH(name) > 0)
// )
try db.create(table: "player") { t in
t.column("name", .text).check { length($0) > 0 }
}
Related SQLite documentation: https://www.sqlite.org/lang_createtable.html#ckconst