RecordBox
public final class RecordBox<T: RowConvertible & MutablePersistable>: Record
RecordBox is a subclass of Record that aims at giving any record type the changes tracking provided by the Record class.
// A Regular record struct
struct Player: RowConvertible, MutablePersistable, Codable {
static let databaseTableName = "players"
var id: Int64?
var name: String
var score: Int
mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
}
}
try dbQueue.inDatabase { db in
// Fetch a player record
let playerRecord = try RecordBox<Player>.fetchOne(db, key: 1)!
// Profit from changes tracking
playerRecord.value.score = 300
playerRecord.hasPersistentChangedValues // true
playerRecord.persistentChangedValues["score"] // 100 (the old value)
}
-
The boxed record
Declaration
Swift
public var value: T
-
Creates a RecordBox that wraps the given record
Declaration
Swift
public init(value: T)
-
Initializes a record from
row
.Declaration
Swift
public required init(row: Row)