Model

public protocol Model : Decodable, Encodable

Protocol Model conforming to Codable defining the available operations

  • tableName Default implementation

    Defines the tableName in the Database

    Default Implementation

    Defaults to the name of the model + “s”

    Declaration

    Swift

    static var tableName: String { get }
  • idColumnName Default implementation

    Defines the id column name in the Database

    Default Implementation

    Defaults to “id”

    Declaration

    Swift

    static var idColumnName: String { get }
  • idColumnType Default implementation

    Defines 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 implementation

    Defines the keypath to the Models id field

    Default Implementation

    Declaration

    Swift

    static var idKeypath: IDKeyPath { get }
  • dateEncodingFormat Default implementation

    Defines the format in which Date properties of the Model will be written to the Database. Defaults to .double

    Default 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:using:_:) Default implementation

    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:using:_:) Default implementation

    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:matching:_:) Default implementation

    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 implementation

    Call to get the table of the model

    Default Implementation

    Declaration

    Swift

    static func getTable() throws -> Table
  • find(id:using:_:) Default implementation

    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:matching:_:) Default implementation

    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
  • 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 execute

    parameters

    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.

  • 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 execute

    parameters

    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.

  • 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 execute

    parameters

    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.

  • 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 execute

    parameters

    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.

  • 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 execute

    parameters

    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.