PrimaryKeyInfo

Information about a primary key.

Database+Schema.swift:1432
struct PrimaryKeyInfo

You get PrimaryKeyInfo instances with the primaryKey(_:in:) Database method.

When the table’s primary key is the rowid:

// CREATE TABLE item (name TEXT)
let pk = try db.primaryKey("item")
pk.columns     // ["rowid"]
pk.rowIDColumn // nil
pk.isRowID     // true

// CREATE TABLE citizen (
//   id INTEGER PRIMARY KEY,
//   name TEXT
// )
let pk = try db.primaryKey("citizen")!
pk.columns     // ["id"]
pk.rowIDColumn // "id"
pk.isRowID     // true

When the table’s primary key is not the rowid:

// CREATE TABLE country (
//   isoCode TEXT NOT NULL PRIMARY KEY
//   name TEXT
// )
let pk = try db.primaryKey("country")!
pk.columns     // ["isoCode"]
pk.rowIDColumn // nil
pk.isRowID     // false

// CREATE TABLE citizenship (
//   citizenID INTEGER NOT NULL REFERENCES citizen(id)
//   countryIsoCode TEXT NOT NULL REFERENCES country(isoCode)
//   PRIMARY KEY (citizenID, countryIsoCode)
// )
let pk = try db.primaryKey("citizenship")!
pk.columns     // ["citizenID", "countryIsoCode"]
pk.rowIDColumn // nil
pk.isRowID     // false