Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update a sqlite table
//where Medicine is an encodable, decodable struct
fileprivate static let medicineTable = Table("medicine")
fileprivate static let counterTable = Table("counter")
fileprivate static let medicineColumn = Expression<Int>("medicine")
fileprivate static let idColumn = Expression<Int64>("id")
static func update(item: Medicine, onCompletion: (Bool, Error?) -> ()) {
guard let db = SQLiteDataEngine.shared.db else {
onCompletion(false, DataAccessError.Database_Connection_Error)
return
}
guard item.id != nil, let itemId = Int64(exactly: item.id!) else {
onCompletion(false, DataAccessError.Nil_In_Data)
return
}
do {
let selected = medicineTable.filter(idColumn == itemId)
_ = try db.run(selected.update(item))
onCompletion(true, nil)
} catch {
onCompletion(false, error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.