Static Methodgrdb 7.4.0GRDB

find(_:key:)

Returns the record identified by a primary key, or throws an error if the record does not exist.

FetchableRecord+TableRecord.swift:211
static func find(_ db: Database, key: some DatabaseValueConvertible) throws -> Self

Parameters

db

A database connection.

key

A primary key value.

Returns

A record.

Throws

A DatabaseError whenever an SQLite error occurs, or a recordNotFound(databaseTableName:key:) if the record does not exist in the database.

For example:

try dbQueue.read { db in
    let player = try Player.find(db, key: 123)
    let country = try Country.find(db, key: "FR")
}