PrimaryKeyInfo
public struct PrimaryKeyInfo
Primary keys are returned from the Database.primaryKey(_:) method.
When the table’s primary key is the rowid:
// CREATE TABLE items (name TEXT)
let pk = try db.primaryKey("items")
pk.columns // ["rowid"]
pk.rowIDColumn // nil
pk.isRowID // true
// CREATE TABLE citizens (
// id INTEGER PRIMARY KEY,
// name TEXT
// )
let pk = try db.primaryKey("citizens")!
pk.columns // ["id"]
pk.rowIDColumn // "id"
pk.isRowID // true
When the table’s primary key is not the rowid:
// CREATE TABLE countries (
// isoCode TEXT NOT NULL PRIMARY KEY
// name TEXT
// )
let pk = db.primaryKey("countries")!
pk.columns // ["isoCode"]
pk.rowIDColumn // nil
pk.isRowID // false
// CREATE TABLE citizenships (
// citizenID INTEGER NOT NULL REFERENCES citizens(id)
// countryIsoCode TEXT NOT NULL REFERENCES countries(isoCode)
// PRIMARY KEY (citizenID, countryIsoCode)
// )
let pk = db.primaryKey("citizenships")!
pk.columns // ["citizenID", "countryIsoCode"]
pk.rowIDColumn // nil
pk.isRowID // false
-
The columns in the primary key; this array is never empty.
Declaration
Swift
public var columns: [String]
-
When not nil, the name of the column that contains the INTEGER PRIMARY KEY.
Declaration
Swift
public var rowIDColumn: String?
-
When true, the primary key is the rowid:
Declaration
Swift
public var isRowID: Bool