Michael
Michael

Reputation: 33297

How to Delete Rows with SQLite.SWIFT?

I use SQLite.SWIFT and want to delete rows with specific id from my table.

The documentation here said that I can use:

let delete = delete.update(email <- "[email protected]")
if let changes = delete.changes where changes > 0 {
    println("deleted alice")
} else if delete.statement.failed {
    println("delete failed: \(delete.statement.reason)")
}

I could not find a global delete function. My table is

let users = db["users"]

How do I perform the delete.update function?

Upvotes: 2

Views: 3503

Answers (1)

Rob
Rob

Reputation: 437452

That would appear to be a typo in the documentation. You can do something like so:

let alice = users.filter(email == "[email protected]")
let delete = alice.delete()
if let changes = delete.changes where changes > 0 {
    println("removed \(changes) record(s) for Alice")
} else if delete.statement.failed {
    println("delete failed: \(delete.statement.reason)")
}

Upvotes: 3

Related Questions