Closed
Description
Fresh to GRDB. Loving it so far.
I can't seem to find documentation on the preferred method for creating objects with auto-incrementing IDs. Lets say I'm creating a table like this.
try db.create(table: "row") { t in
t.autoIncrementedPrimaryKey("id")
}
First of all, should this property be Int
or Int64
? Then, how should the property be defined in the corresponding record?
struct Row: ... {
let id: Int
// or
let id: Int!
// or
let id: Int?
}
It seems like it needs to be either optional or implicitly-unwrapped-optional, because just initing with Row(id: 0).insertAndFetch(db)
crashes due to non-unique IDs. Initing the model with Row(id: nil).insertAndFetch(db)
works, but that requires the Optional/IUO.
Is using IUO's the intended method for creating objects with auto-incremented IDs?