Instance Methodgrdb 7.3.0GRDB

foreignKeys(on:in:)

Returns the foreign keys defined on table named tableName.

Database+Schema.swift:723
func foreignKeys(on tableName: String, in schemaName: String? = nil) throws -> [ForeignKeyInfo]

Throws

A DatabaseError whenever an SQLite error occurs, if the specified schema does not exist, or if no such table or view with this name exists in the main or temp schema, or in an attached database.

When schemaName is not specified, known schemas are iterated in SQLite resolution order and the first matching result is returned.

For example:

try dbQueue.read { db in
    let foreignKeys = try db.foreignKeys(in: "player")
    for foreignKey in foreignKeys {
        print(foreignKey.destinationTable)
    }
}