static var databaseColumnDecodingStrategy: DatabaseColumnDecodingStrategy
The default strategy for converting column names to coding keys is useDefaultKeys
.
static var databaseColumnEncodingStrategy: DatabaseColumnEncodingStrategy
Returns the default strategy for converting coding keys to column names: useDefaultKeys
.
static var databaseDecodingUserInfo: [CodingUserInfoKey : Any]
Contextual information made available to the Decodable.init(from:)
initializer.
static var databaseEncodingUserInfo: [CodingUserInfoKey : Any]
Contextual information made available to the Encodable.encode(to:)
method.
static var databaseSelection: [any SQLSelectable]
The default selection is all columns: [.allColumns]
.
static var databaseTableName: String
The default name of the database table is derived from the name of the type.
static var persistenceConflictPolicy: PersistenceConflictPolicy
static func aliased(TableAlias) -> QueryInterfaceRequest<Self>
Returns a request that can be referred to with the provided alias.
static func all() -> QueryInterfaceRequest<Self>
Returns a request for all records in the table.
static func annotated(with: any SQLSelectable...) -> QueryInterfaceRequest<Self>
Returns a request with the provided result columns appended to the record selection.
static func annotated(with: AssociationAggregate<Self>...) -> QueryInterfaceRequest<Self>
Returns a request with the given association aggregates appended to the record selection.
static func annotated(with: [any SQLSelectable]) -> QueryInterfaceRequest<Self>
Returns a request with the provided result columns appended to the record selection.
static func annotated(with: [AssociationAggregate<Self>]) -> QueryInterfaceRequest<Self>
Returns a request with the given association aggregates appended to the record selection.
static func annotated<A>(withOptional: A) -> QueryInterfaceRequest<Self>
Returns a request with the columns of the eventual associated record appended to the record selection.
static func annotated<A>(withRequired: A) -> QueryInterfaceRequest<Self>
Returns a request with the columns of the associated record appended to the record selection. Records that do not have an associated record are discarded.
static func association<Destination>(to: CommonTableExpression<Destination>) -> JoinAssociation<Self, Destination>
Creates an association to a common table expression.
static func association<Destination>(to: CommonTableExpression<Destination>, on: @escaping (_ left: TableAlias, _ right: TableAlias) -> any SQLExpressible) -> JoinAssociation<Self, Destination>
Creates an association to a common table expression.
static func belongsTo<Destination>(Table<Destination>, key: String?, using: ForeignKey?) -> BelongsToAssociation<Self, Destination>
Creates a BelongsToAssociation
between Self
and the destination Table
.
static func belongsTo<Destination>(Destination.Type, key: String?, using: ForeignKey?) -> BelongsToAssociation<Self, Destination>
Creates a BelongsToAssociation
between Self
and the destination TableRecord
type.
static func databaseDataDecodingStrategy(for: String) -> DatabaseDataDecodingStrategy
The default strategy for decoding Data
columns is deferredToData
.
static func databaseDataEncodingStrategy(for: String) -> DatabaseDataEncodingStrategy
Returns the default strategy for encoding Data
columns: deferredToData
.
static func databaseDateDecodingStrategy(for: String) -> DatabaseDateDecodingStrategy
The default strategy for decoding Date
columns is deferredToDate
.
static func databaseDateEncodingStrategy(for: String) -> DatabaseDateEncodingStrategy
Returns the default strategy for encoding Date
columns: deferredToDate
.
static func databaseJSONDecoder(for: String) -> JSONDecoder
Returns the JSONDecoder
that decodes the value for a given column.
static func databaseJSONEncoder(for: String) -> JSONEncoder
Returns the JSONEncoder
that encodes the value for a given column.
static func databaseUUIDEncodingStrategy(for: String) -> DatabaseUUIDEncodingStrategy
Returns the default strategy for encoding UUID
columns: deferredToUUID
.
static func deleteAll(Database) throws -> Int
Deletes all records, and returns the number of deleted records.
static func deleteAll(Database, keys: [[String : (any DatabaseValueConvertible)?]]) throws -> Int
Deletes records identified by their primary or unique keys, and returns the number of deleted records.
static func deleteAll(Database, keys: some Collection<some DatabaseValueConvertible>) throws -> Int
Deletes records identified by their primary keys, and returns the number of deleted records.
static func deleteOne(Database, key: [String : (any DatabaseValueConvertible)?]) throws -> Bool
Deletes the record identified by its primary or unique key, and returns whether a record was deleted.
static func deleteOne(Database, key: some DatabaseValueConvertible) throws -> Bool
Deletes the record identified by its primary key, and returns whether a record was deleted.
static func exists(Database, key: [String : (any DatabaseValueConvertible)?]) throws -> Bool
Returns whether a record exists for this primary or unique key.
static func exists(Database, key: some DatabaseValueConvertible) throws -> Bool
Returns whether a record exists for this primary key.
static func fetchAll(Database) throws -> [Self]
Returns an array of all records fetched from the database.
static func fetchAll(Database, some FetchRequest) throws -> [Self]
Returns an array of records fetched from a fetch request.
static func fetchAll(Statement, arguments: StatementArguments?, adapter: (any RowAdapter)?) throws -> [Self]
Returns an array of records fetched from a prepared statement.
static func fetchAll(Database, keys: [[String : (any DatabaseValueConvertible)?]]) throws -> [Self]
Returns an array of records identified by the provided unique keys (primary key or any key with a unique index on it).
static func fetchAll(Database, keys: some Collection<some DatabaseValueConvertible>) throws -> [Self]
Returns an array of records identified by their primary keys.
static func fetchAll(Database, sql: String, arguments: StatementArguments, adapter: (any RowAdapter)?) throws -> [Self]
Returns an array of records fetched from an SQL query.
static func fetchCount(Database) throws -> Int
Returns the number of records in the database table.
static func fetchCursor(Database) throws -> RecordCursor<Self>
Returns a cursor over all records fetched from the database.
static func fetchCursor(Database, some FetchRequest) throws -> RecordCursor<Self>
Returns a cursor over records fetched from a fetch request.
static func fetchCursor(Statement, arguments: StatementArguments?, adapter: (any RowAdapter)?) throws -> RecordCursor<Self>
Returns a cursor over records fetched from a prepared statement.
static func fetchCursor(Database, keys: [[String : (any DatabaseValueConvertible)?]]) throws -> RecordCursor<Self>
Returns a cursor over records identified by the provided unique keys (primary key or any key with a unique index on it).
static func fetchCursor(Database, keys: some Collection<some DatabaseValueConvertible>) throws -> RecordCursor<Self>
Returns a cursor over records identified by their primary keys.
static func fetchCursor(Database, sql: String, arguments: StatementArguments, adapter: (any RowAdapter)?) throws -> RecordCursor<Self>
Returns a cursor over records fetched from an SQL query.
static func fetchOne(Database) throws -> Self?
Returns a single record fetched from the database.
static func fetchOne(Database, some FetchRequest) throws -> Self?
Returns a single record fetched from a fetch request.
static func fetchOne(Statement, arguments: StatementArguments?, adapter: (any RowAdapter)?) throws -> Self?
Returns a single record fetched from a prepared statement.
static func fetchOne(Database, key: [String : (any DatabaseValueConvertible)?]?) throws -> Self?
Returns the record identified by a unique key (the primary key or any key with a unique index on it).
static func fetchOne(Database, key: some DatabaseValueConvertible) throws -> Self?
Returns the record identified by a primary key.
static func fetchOne(Database, sql: String, arguments: StatementArguments, adapter: (any RowAdapter)?) throws -> Self?
Returns a single record fetched from an SQL query.
static func filter(some SQLSpecificExpressible) -> QueryInterfaceRequest<Self>
Returns a request filtered with a boolean SQL expression.
static func filter(key: [String : (any DatabaseValueConvertible)?]?) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary or unique key.
static func filter(key: some DatabaseValueConvertible) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(keys: [[String : (any DatabaseValueConvertible)?]]) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary or unique key.
static func filter(keys: some Collection<some DatabaseValueConvertible>) -> QueryInterfaceRequest<Self>
Returns a request filtered by primary key.
static func filter(literal: SQL) -> QueryInterfaceRequest<Self>
Returns a request filtered with an SQL
literal.
static func filter(sql: String, arguments: StatementArguments) -> QueryInterfaceRequest<Self>
Returns a request filtered with an SQL string.
static func find(Database, key: [String : (any DatabaseValueConvertible)?]) throws -> Self
Returns the record identified by a unique key (the primary key or any key with a unique index on it), or throws an error if the record does not exist.
static func find(Database, key: some DatabaseValueConvertible) throws -> Self
Returns the record identified by a primary key, or throws an error if the record does not exist.
static func hasMany<Destination>(Table<Destination>, key: String?, using: ForeignKey?) -> HasManyAssociation<Self, Destination>
Creates a HasManyAssociation
between Self
and the destination Table
.
static func hasMany<Destination>(Destination.Type, key: String?, using: ForeignKey?) -> HasManyAssociation<Self, Destination>
Creates a HasManyAssociation
between Self
and the destination TableRecord
type.
static func hasMany<Pivot, Target>(Target.RowDecoder.Type, through: Pivot, using: Target, key: String?) -> HasManyThroughAssociation<Self, Target.RowDecoder>
Creates a HasManyThroughAssociation
between Self
and the destination TableRecord
type.
static func hasOne<Destination>(Table<Destination>, key: String?, using: ForeignKey?) -> HasOneAssociation<Self, Destination>
Creates a HasOneAssociation
between Self
and the destination Table
.
static func hasOne<Destination>(Destination.Type, key: String?, using: ForeignKey?) -> HasOneAssociation<Self, Destination>
Creates a HasOneAssociation
between Self
and the destination TableRecord
type.
static func hasOne<Pivot, Target>(Target.RowDecoder.Type, through: Pivot, using: Target, key: String?) -> HasOneThroughAssociation<Self, Target.RowDecoder>
Creates a HasOneThroughAssociation
between Self
and the destination TableRecord
type.
static func having(AssociationAggregate<Self>) -> QueryInterfaceRequest<Self>
Returns a request filtered according to the provided association aggregate.
static func including<A>(all: A) -> QueryInterfaceRequest<Self>
Returns a request that fetches all records associated with each record in this request.
static func including<A>(optional: A) -> QueryInterfaceRequest<Self>
Returns a request that fetches the eventual record associated with each record of this request.
static func including<A>(required: A) -> QueryInterfaceRequest<Self>
Returns a request that fetches the record associated with each record in this request. Records that do not have an associated record are discarded.
static func joining<A>(optional: A) -> QueryInterfaceRequest<Self>
Returns a request that joins each record of this request to its eventual associated record.
static func joining<A>(required: A) -> QueryInterfaceRequest<Self>
Returns a request that joins each record of this request to its associated record. Records that do not have an associated record are discarded.
static func limit(Int, offset: Int?) -> QueryInterfaceRequest<Self>
Returns a limited request.
static func matching(FTS3Pattern?) -> QueryInterfaceRequest<Self>
Returns a request filtered on records that match an FTS3
full-text pattern.
static func matching(FTS5Pattern?) -> QueryInterfaceRequest<Self>
Returns a request filtered on records that match an FTS5
full-text pattern.
static func none() -> QueryInterfaceRequest<Self>
Returns an empty request that fetches no record.
static func numberOfSelectedColumns(Database) throws -> Int
Returns the number of selected columns.
static func order(any SQLOrderingTerm...) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL ordering terms.
static func order([any SQLOrderingTerm]) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL ordering terms.
static func order(literal: SQL) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL
literal.
static func order(sql: String, arguments: StatementArguments) -> QueryInterfaceRequest<Self>
Returns a request sorted according to the given SQL string.
static func orderByPrimaryKey() -> QueryInterfaceRequest<Self>
Returns a request sorted by primary key.
static func recordNotFound(Database, key: some DatabaseValueConvertible) -> any Error
Returns an error for a record that does not exist in the database.
static func recordNotFound(key: [String : (any DatabaseValueConvertible)?]) -> RecordError
Returns an error for a record that does not exist in the database.
static func select(any SQLSelectable...) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided result columns.
static func select([any SQLSelectable]) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided result columns.
static func select<RowDecoder>(any SQLSelectable..., as: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided result columns, and defines the type of decoded rows.
static func select<RowDecoder>([any SQLSelectable], as: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided result columns, and defines the type of decoded rows.
static func select(literal: SQL) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided SQL
literal.
static func select<RowDecoder>(literal: SQL, as: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided SQL
literal, and defines the type of decoded rows.
static func select(sql: String, arguments: StatementArguments) -> QueryInterfaceRequest<Self>
Returns a request that selects the provided SQL string.
static func select<RowDecoder>(sql: String, arguments: StatementArguments, as: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder>
Returns a request that selects the provided SQL string, and defines the type of decoded rows.
static func selectID() -> QueryInterfaceRequest<Self.ID>
Returns a request that selects the primary key.
static func selectPrimaryKey<PrimaryKey>(as: PrimaryKey.Type) -> QueryInterfaceRequest<PrimaryKey>
Returns a request that selects the primary key.
static func updateAll(Database, onConflict: Database.ConflictResolution?, ColumnAssignment...) throws -> Int
Updates all records, and returns the number of updated records.
static func updateAll(Database, onConflict: Database.ConflictResolution?, [ColumnAssignment]) throws -> Int
Updates all records, and returns the number of updated records.
static func with<RowDecoder>(CommonTableExpression<RowDecoder>) -> QueryInterfaceRequest<Self>
Returns a request that embeds a common table expression.
var databaseDictionary: [String : DatabaseValue]
A dictionary whose keys are the columns encoded in the doc:/documentation/GRDB/EncodableRecord/encode(to:)-k9pf method.
func databaseChanges(from: some EncodableRecord) throws -> [String : DatabaseValue]
Returns a dictionary of values changed from the other record.
func databaseChanges(modify: (inout Self) throws -> Void) throws -> [String : DatabaseValue]
Modifies the record according to the provided modify
closure, and returns a dictionary of changed values.
func databaseEquals(Self) -> Bool
Returns a boolean indicating whether this record and the other record have the same database representation.
func delete(Database) throws -> Bool
Executes a DELETE statement.
func exists(Database) throws -> Bool
Returns whether the primary key of the record matches a row in the database.
func insert(Database, onConflict: Database.ConflictResolution?) throws
Executes an INSERT
statement.
func insertAndFetch(Database, onConflict: Database.ConflictResolution?) throws -> Self
Executes an INSERT RETURNING
statement, and returns a new record built from the inserted row.
func insertAndFetch<T>(Database, onConflict: Database.ConflictResolution?, as: T.Type) throws -> T
Executes an INSERT RETURNING
statement, and returns a new record built from the inserted row.
func insertAndFetch<T>(Database, onConflict: Database.ConflictResolution?, selection: [any SQLSelectable], fetch: (Statement) throws -> T) throws -> T
Executes an INSERT RETURNING
statement, and returns the selected columns from the inserted row.
func inserted(Database, onConflict: Database.ConflictResolution?) throws -> Self
Executes an INSERT
statement, and returns the inserted record.
func recordNotFound(Database) -> any Error
Returns an error that tells that the record does not exist in the database.
func request<A>(for: A) -> QueryInterfaceRequest<A.RowDecoder>
Returns a request for the associated record(s).
func save(Database, onConflict: Database.ConflictResolution?) throws
Executes an INSERT
or UPDATE
statement.
func saveAndFetch(Database, onConflict: Database.ConflictResolution?) throws -> Self
Executes an INSERT RETURNING
or UPDATE RETURNING
statement, and returns a new record built from the saved row.
func saveAndFetch<T>(Database, onConflict: Database.ConflictResolution?, as: T.Type) throws -> T
Executes an INSERT RETURNING
or UPDATE RETURNING
statement, and returns a new record built from the saved row.
func saveAndFetch<T>(Database, onConflict: Database.ConflictResolution?, selection: [any SQLSelectable], fetch: (Statement) throws -> T) throws -> T
Executes an INSERT RETURNING
or UPDATE RETURNING
statement, and returns the selected columns from the saved row.
func saved(Database, onConflict: Database.ConflictResolution?) throws -> Self
Executes an INSERT
or UPDATE
statement, and returns the saved record.
func update(Database, onConflict: Database.ConflictResolution?) throws
Executes an UPDATE
statement on all columns.
func update(Database, onConflict: Database.ConflictResolution?, columns: some Collection<some ColumnExpression>) throws
Executes an UPDATE
statement on the provided columns.
func update(Database, onConflict: Database.ConflictResolution?, columns: some Collection<String>) throws
Executes an UPDATE
statement on the provided columns.
func updateAndFetch(Database, onConflict: Database.ConflictResolution?) throws -> Self
Executes an UPDATE RETURNING
statement on all columns, and returns a new record built from the updated row.
func updateAndFetch<T>(Database, onConflict: Database.ConflictResolution?, as: T.Type) throws -> T
Executes an UPDATE RETURNING
statement on all columns, and returns a new record built from the updated row.
func updateAndFetch<T>(Database, onConflict: Database.ConflictResolution?, columns: some Collection<some ColumnExpression>, selection: [any SQLSelectable], fetch: (Statement) throws -> T) throws -> T
Executes an UPDATE RETURNING
statement on the provided columns, and returns the selected columns from the updated row.
func updateAndFetch<T>(Database, onConflict: Database.ConflictResolution?, columns: some Collection<String>, selection: [any SQLSelectable], fetch: (Statement) throws -> T) throws -> T
Executes an UPDATE RETURNING
statement on the provided columns, and returns the selected columns from the updated row.
func updateAndFetch<T>(Database, onConflict: Database.ConflictResolution?, selection: [any SQLSelectable], fetch: (Statement) throws -> T) throws -> T
Executes an UPDATE RETURNING
statement on all columns, and returns the selected columns from the updated row.
func updateChanges(Database, onConflict: Database.ConflictResolution?, modify: (inout Self) throws -> Void) throws -> Bool
Modifies the record according to the provided modify
closure, and executes an UPDATE
statement that updates the modified columns, if and only if the record was modified.
func updateChangesAndFetch<T>(Database, onConflict: Database.ConflictResolution?, as: T.Type, modify: (inout Self) throws -> Void) throws -> T?
Modifies the record according to the provided modify
closure, and executes an UPDATE RETURNING
statement that updates the modified columns, if and only if the record was modified. The method returns a new record built from the updated row.
func updateChangesAndFetch(Database, onConflict: Database.ConflictResolution?, modify: (inout Self) throws -> Void) throws -> Self?
Modifies the record according to the provided modify
closure, and executes an UPDATE RETURNING
statement that updates the modified columns, if and only if the record was modified. The method returns a new record built from the updated row.
func updateChangesAndFetch<T>(Database, onConflict: Database.ConflictResolution?, selection: [any SQLSelectable], fetch: (Statement) throws -> T, modify: (inout Self) throws -> Void) throws -> T?
Modifies the record according to the provided modify
closure, and executes an UPDATE RETURNING
statement that updates the modified columns, if and only if the record was modified. The method returns a new record built from the updated row.
func upsert(Database) throws
Executes an INSERT ON CONFLICT DO UPDATE
statement.
func upsertAndFetch<T>(Database, as: T.Type, onConflict: [String], doUpdate: ((_ excluded: TableAlias) -> [ColumnAssignment])?) throws -> T
Executes an INSERT ON CONFLICT DO UPDATE RETURNING
statement, and returns the upserted record.
func upsertAndFetch(Database, onConflict: [String], doUpdate: ((_ excluded: TableAlias) -> [ColumnAssignment])?) throws -> Self
Executes an INSERT ON CONFLICT DO UPDATE RETURNING
statement, and returns the upserted record.