import Foundation import GRDB struct Settings: DBStorable { static let databaseTableName = "settings" let bareJid: String var omemoRegId: Int var id: String { bareJid } } extension Settings { static func getFor(_ bareJid: String) -> Settings? { do { return try Database.shared.dbQueue.read { db in let settings = try Settings.filter(Column("bareJid") == bareJid).fetchOne(db) return settings } } catch { logIt(.error, "Settings not exists for \(bareJid)") return nil } } func wipeOmemoRegId() { do { _ = try Database.shared.dbQueue.write { db in try Settings .filter(Column("bareJid") == bareJid) .updateAll(db, Column("omemoRegId").set(to: 0)) } } catch { logIt(.error, "Failed to wipe omemoRegId for \(bareJid)") } } func save() { do { try Database.shared.dbQueue.write { db in try self.insert(db) } } catch { logIt(.error, "Failed to save settings for \(bareJid)") } } }