Static Methodgrdb 7.1.0GRDB

exists(_:id:)

Returns whether a record exists for this primary key.

TableRecord.swift:371
static func exists(_ db: Database, id: ID) throws -> Bool

Parameters

db

A database connection.

id

A primary key value.

Returns

Whether a record exists for this primary key.

All single-column primary keys are supported:

struct Player: TableRecord, Identifiable {
    var id: Int64
}
struct Country: TableRecord, Identifiable {
    var id: String
}

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