Model
public protocol Model : Decodable, Encodable
Protocol Model conforming to Codable defining the available operations
-
tableName
Default implementationDefines the tableName in the Database
Default Implementation
Defaults to the name of the model + “s”
Declaration
Swift
static var tableName: String { get }
-
idColumnName
Default implementationDefines the id column name in the Database
Default Implementation
Defaults to “id”
Declaration
Swift
static var idColumnName: String { get }
-
idColumnType
Default implementationDefines the id column type in the Database
Default Implementation
Defaults to Int64
Declaration
Swift
static var idColumnType: SQLDataType.Type { get }
-
Defines typealias for the id fields keypath
Declaration
Swift
typealias IDKeyPath = WritableKeyPath<Self, Int?>?
-
idKeypath
Default implementationDefines the keypath to the Models id field
Default Implementation
Declaration
Swift
static var idKeypath: IDKeyPath { get }
-
dateEncodingFormat
Default implementationDefines the format in which
Date
properties of theModel
will be written to the Database. Defaults to .doubleDefault Implementation
Declaration
Swift
static var dateEncodingFormat: DateEncodingFormat { get }
-
createTableSync(using:
Default implementation) Call to create the table in the database synchronously
Default Implementation
Declaration
Swift
static func createTableSync(using db: Database?) throws -> Bool
-
createTable(using:
Default implementation_: ) Call to create the table in the database asynchronously
Default Implementation
Declaration
Swift
static func createTable(using db: Database?, _ onCompletion: @escaping (Bool?, RequestError?) -> Void)
-
dropTableSync(using:
Default implementation) Call to drop the table in the database synchronously
Default Implementation
Declaration
Swift
static func dropTableSync(using db: Database?) throws -> Bool
-
dropTable(using:
Default implementation_: ) Call to drop the table in the database asynchronously
Default Implementation
Declaration
Swift
static func dropTable(using db: Database?, _ onCompletion: @escaping (Bool?, RequestError?) -> Void)
-
save(using:
Default implementation_: ) Call to save a model to the database that accepts a completion handler. The callback is passed a model or an error
Default Implementation
Undocumented
Declaration
Swift
func save(using db: Database?, _ onCompletion: @escaping (Self?, RequestError?) -> Void)
-
Call to save a model to the database that accepts a completion handler. The callback is passed an id, a model or an error
Declaration
Swift
func save<I>(using db: Database?, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) where I : Identifier
-
update(id:
Default implementationusing: _: ) Call to update a model in the database with an id that accepts a completion handler. The callback is passed a updated model or an error
Default Implementation
Declaration
Swift
func update<I>(id: I, using db: Database?, _ onCompletion: @escaping (Self?, RequestError?) -> Void) where I : Identifier
-
delete(id:
Default implementationusing: _: ) Call to delete a model in the database with an id that accepts a completion handler. The callback is passed an optional error
Default Implementation
Declaration
Swift
static func delete(id: Identifier, using db: Database?, _ onCompletion: @escaping (RequestError?) -> Void)
-
deleteAll(using:
Default implementation_: ) Call to delete all the models in the database that accepts a completion handler. The callback is passed an optional error
Default Implementation
Declaration
Swift
static func deleteAll(using db: Database?, _ onCompletion: @escaping (RequestError?) -> Void)
-
deleteAll(using:
Default implementationmatching: _: ) Call to delete all the models in the database mathcing the QueryParams that accepts a completion handler. The callback is passed an optional error
Default Implementation
Delete all the models matching the QueryParams
Declaration
Swift
static func deleteAll<Q>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping (RequestError?) -> Void) where Q : QueryParams
-
getTable()
Default implementationCall to get the table of the model
Default Implementation
Declaration
Swift
static func getTable() throws -> Table
-
find(id:
Default implementationusing: _: ) Call to find a model in the database with an id that accepts a completion handler. The callback is passed the model or an error
Default Implementation
Find a model with an id
Declaration
Swift
static func find<I>(id: I, using db: Database?, _ onCompletion: @escaping (Self?, RequestError?) -> Void) where I : Identifier
-
findAll(using:
Default implementation_: ) Call to find all the models in the database that accepts a completion handler. The callback is passed an array of models or an error
Default Implementation
Find all the models
Declaration
Swift
static func findAll(using db: Database?, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void)
-
Call to find all the models in the database that accepts a completion handler. The callback is passed an array of tuples (id, model) or an error
Declaration
Swift
static func findAll<I>(using db: Database?, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) where I : Identifier
-
Call to find all the models in the database that accepts a completion handler. The callback is passed a dictionary [id: model] or an error
Declaration
Swift
static func findAll<I>(using db: Database?, _ onCompletion: @escaping ([I : Self]?, RequestError?) -> Void) where I : Identifier, I : Hashable
-
findAll(using:
Default implementationmatching: _: ) Call to find all the models in the database matching the QueryParams that accepts a completion handler. The callback is passed an array of models or an error
Default Implementation
Find all the models matching the QueryParams
Declaration
Swift
static func findAll<Q>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) where Q : QueryParams
-
Call to find all the models in the database matching the QueryParams that accepts a completion handler. The callback is passed an array of tuples (id, model) or an error
Declaration
Swift
static func findAll<Q, I>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) where Q : QueryParams, I : Identifier
-
Call to find all the models in the database matching the QueryParams that accepts a completion handler. The callback is passed a dictionary [id: model] or an error
Declaration
Swift
static func findAll<Q, I>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([I : Self]?, RequestError?) -> Void) where Q : QueryParams, I : Identifier, I : Hashable
-
executeQuery(query:
Extension methodparameters: using: _: ) Allows custom functions on a model to query the database directly.
Declaration
Swift
static func executeQuery(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void)
Parameters
query
The
Query
to executeparameters
An optional array of parameters to pass to the query
using
Optional Database to use
onCompletion
The function to be called when the execution of the query has completed. The function will be passed a tuple of (Self?, RequestError?), of which one will be nil, depending on whether the query was successful.
-
executeQuery(query:
Extension methodparameters: using: _: ) Allows custom functions on a model to query the database directly.
Declaration
Swift
static func executeQuery<I>(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) where I : Identifier
Parameters
query
The
Query
to executeparameters
An optional array of parameters to pass to the query
using
Optional Database to use
onCompletion
The function to be called when the execution of the query has completed. The function will be passed a tuple of (Identifier?, Self?, RequestError?), of which some will be nil, depending on whether the query was successful.
-
executeQuery(query:
Extension methodparameters: using: _: ) Allows custom functions on a model to query the database directly.
Declaration
Swift
static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void)
Parameters
query
The
Query
to executeparameters
An optional array of parameters to pass to the query
using
Optional Database to use
onCompletion
The function to be called when the execution of the query has completed. The function will be passed a tuple of ([Self]?, RequestError?), of which one will be nil, depending on whether the query was successful.
-
executeQuery(query:
Extension methodparameters: using: _: ) Allows custom functions on a model to query the database directly.
Declaration
Swift
static func executeQuery<I>(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) where I : Identifier
Parameters
query
The
Query
to executeparameters
An optional array of parameters to pass to the query
using
Optional Database to use
onCompletion
The function to be called when the execution of the query has completed. The function will be passed a tuple of ([Identifier, Self]?, RequestError?), of which one will be nil, depending on whether the query was successful.
-
executeQuery(query:
Extension methodparameters: using: _: ) Allows custom functions on a model to query the database directly.
Declaration
Swift
static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping (RequestError?) -> Void)
Parameters
query
The
Query
to executeparameters
An optional array of parameters to pass to the query
using
Optional Database to use
onCompletion
The function to be called when the execution of the query has completed. The function will be passed a RequestError? which may be nil, depending on whether the query was successful.