Static Methodgrdb 7.2.0GRDB

exists(_:key:)

Returns whether a record exists for this primary key.

TableRecord.swift:344
static func exists(_ db: Database, key: some DatabaseValueConvertible) throws -> Bool

Parameters

db

A database connection.

key

A primary key value.

Returns

Whether a record exists for this primary key.

All single-column primary keys are supported:

struct Player: TableRecord { }
struct Country: TableRecord { }

try dbQueue.read { db in
    let playerExists = try Player.exists(db, key: 1)
    let countryExists = try Country.exists(db, key: "FR")
}