Model
public protocol Model: Codable
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
-
idColumnName
Default implementationDefines the id column name in the Database
Default Implementation
Defaults to
id
Declaration
Swift
static var idColumnName: String
-
idColumnType
Default implementationDefines the id column type in the Database
Default Implementation
Defaults to Int64
Declaration
Swift
static var idColumnType: SQLDataType.Type
-
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
-
createTableSync(using:)
Default implementationCall to create the table in the database synchronously
Default Implementation
Declaration
Swift
static func createTableSync(using db: Database?) throws -> Bool
-
createTable(using:_:)
Default implementationCall 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 implementationCall to drop the table in the database synchronously
Default Implementation
Declaration
Swift
static func dropTableSync(using db: Database?) throws -> Bool
-
dropTable(using:_:)
Default implementationCall 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 implementationCall to save a model to the database that accepts a completion handler. The callback is passed a model or an error
Default Implementation
Undocumented
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: Identifier>(using db: Database?, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void)
-
update(id:using:_:)
Default implementationCall 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: Identifier>(id: I, using db: Database?, _ onCompletion: @escaping (Self?, RequestError?) -> Void)
-
delete(id:using:_:)
Default implementationCall 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 implementationCall 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:matching:_:)
Default implementationCall 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: QueryParams>(using db: Database?, matching queryParams:Q?, _ onCompletion: @escaping (RequestError?) -> Void)
-
getTable()
Default implementationCall to get the table of the model
Default Implementation
Declaration
Swift
static func getTable() throws -> Table
-
find(id:using:_:)
Default implementationCall 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: Identifier>(id: I, using db: Database?, _ onCompletion: @escaping (Self?, RequestError?) -> Void)
-
findAll(using:_:)
Default implementationCall 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: Identifier>(using db: Database?, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void)
-
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: Identifier>(using db: Database?, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void)
-
findAll(using:matching:_:)
Default implementationCall 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
Find all the models matching the QueryParams
Declaration
Swift
static func findAll<Q: QueryParams>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void)
-
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: QueryParams, I: Identifier>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void)
-
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: QueryParams, I: Identifier>(using db: Database?, matching queryParams: Q?, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void)
-
executeQuery(query:parameters:using:_:)
Extension methodAllows custom functions on a model to query the database directly.
Declaration
Swift
public 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:parameters:using:_:)
Extension methodAllows custom functions on a model to query the database directly.
Declaration
Swift
public static func executeQuery<I: Identifier>(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (I?, 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 (Identifier?, Self?, RequestError?), of which some will be nil, depending on whether the query was successful.
-
executeQuery(query:parameters:using:_:)
Extension methodAllows custom functions on a model to query the database directly.
Declaration
Swift
public 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:parameters:using:_:)
Extension methodAllows custom functions on a model to query the database directly.
Declaration
Swift
public static func executeQuery<I: Identifier>(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping ([(I, 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 ([Identifier, Self]?, RequestError?), of which one will be nil, depending on whether the query was successful.
-
executeQuery(query:parameters:using:_:)
Extension methodAllows custom functions on a model to query the database directly.
Declaration
Swift
public 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.