let alice = users.filter(id == 1)
do {
if try db.run(alice.update(email <- "[email protected]")) > 0 {
print("updated alice")
} else {
print("alice not found")
}
} catch {
print("update failed: (error)")
}
How should I do in order to update many field in a record
Example: I would like to update (email, name, age) of an user with id = 1, But I just found we only can update one field at once
Please Help. Thank you guys so much.
You create an array of Setters:
var values = [Setter]()
Then you append your Setters as needed and finally execute .update(values).
You can separate each column setter with a comma.
For example:
let alice = users.filter(id == 1)
try db.run(alice.update(
email <- "[email protected]",
name <- "Alice",
age <- 24))
Not a bug, closing.
@anthonyjosephfarina This throws an "Extra call in argument" error for me, this resolved the error:
let alice = users.filter(id == 1)
try db.run(alice.update(
[email <- "[email protected]",
name <- "Alice",
age <- 24]))
@robert-cronin
Thanks for the information!
the [] is SUPER important and saved my day!
I did not notice the difference at first.
Most helpful comment
@anthonyjosephfarina This throws an "Extra call in argument" error for me, this resolved the error: