A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/groue/GRDB.swift/issues/1435 below:

What's the "right" way to use `autoIncrementedPrimaryKey`? · Issue #1435 · groue/GRDB.swift · GitHub

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?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4