From ae4fe3ea1447b2299824182345dcb7ab8bbb974d Mon Sep 17 00:00:00 2001 From: kilnerm <38245247+kilnerm@users.noreply.github.com> Date: Mon, 1 Apr 2019 13:35:55 +0100 Subject: [PATCH] Correct case of idKeypath in README example (#107) --- README.md | 2 +- docs/Classes.html | 2 +- docs/Classes/Database.html | 2 +- docs/Classes/DatabaseDecoder.html | 2 +- docs/Classes/DatabaseEncoder.html | 2 +- docs/Extensions.html | 2 +- docs/Extensions/RequestError.html | 2 +- docs/Protocols.html | 2 +- docs/Protocols/Model.html | 492 +++++++++++++++++- docs/Typealiases.html | 2 +- .../Contents/Resources/Documents/Classes.html | 2 +- .../Resources/Documents/Classes/Database.html | 2 +- .../Documents/Classes/DatabaseDecoder.html | 2 +- .../Documents/Classes/DatabaseEncoder.html | 2 +- .../Resources/Documents/Extensions.html | 2 +- .../Documents/Extensions/RequestError.html | 2 +- .../Resources/Documents/Protocols.html | 2 +- .../Resources/Documents/Protocols/Model.html | 492 +++++++++++++++++- .../Resources/Documents/Typealiases.html | 2 +- .../Contents/Resources/Documents/index.html | 157 +++++- .../Contents/Resources/Documents/search.json | 2 +- .../Contents/Resources/docSet.dsidx | Bin 28672 -> 36864 bytes docs/docsets/SwiftKueryORM.tgz | Bin 80050 -> 84907 bytes docs/index.html | 157 +++++- docs/search.json | 2 +- docs/undocumented.json | 4 +- 26 files changed, 1285 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 1651792..03f6a31 100644 --- a/README.md +++ b/README.md @@ -365,7 +365,7 @@ struct Person: Model { var surname: String var age: Int - static var idKeyPath: IDKeyPath = \Person.id + static var idKeypath: IDKeyPath = \Person.id } ``` diff --git a/docs/Classes.html b/docs/Classes.html index 331e747..f9bcd01 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -282,7 +282,7 @@

Declaration

diff --git a/docs/Classes/Database.html b/docs/Classes/Database.html index 90e8997..e57c354 100644 --- a/docs/Classes/Database.html +++ b/docs/Classes/Database.html @@ -366,7 +366,7 @@

Declaration

diff --git a/docs/Classes/DatabaseDecoder.html b/docs/Classes/DatabaseDecoder.html index 630771a..b87b7de 100644 --- a/docs/Classes/DatabaseDecoder.html +++ b/docs/Classes/DatabaseDecoder.html @@ -181,7 +181,7 @@

Declaration

diff --git a/docs/Classes/DatabaseEncoder.html b/docs/Classes/DatabaseEncoder.html index 9c81680..4ab0cdc 100644 --- a/docs/Classes/DatabaseEncoder.html +++ b/docs/Classes/DatabaseEncoder.html @@ -181,7 +181,7 @@

Declaration

diff --git a/docs/Extensions.html b/docs/Extensions.html index 3a3f249..cefc5e2 100644 --- a/docs/Extensions.html +++ b/docs/Extensions.html @@ -175,7 +175,7 @@

Declaration

diff --git a/docs/Extensions/RequestError.html b/docs/Extensions/RequestError.html index 57d3688..ac3958f 100644 --- a/docs/Extensions/RequestError.html +++ b/docs/Extensions/RequestError.html @@ -451,7 +451,7 @@

Declaration

diff --git a/docs/Protocols.html b/docs/Protocols.html index 675e8f1..93b9a0f 100644 --- a/docs/Protocols.html +++ b/docs/Protocols.html @@ -175,7 +175,7 @@

Declaration

diff --git a/docs/Protocols/Model.html b/docs/Protocols/Model.html index 511b7e6..e43f774 100644 --- a/docs/Protocols/Model.html +++ b/docs/Protocols/Model.html @@ -251,6 +251,67 @@

Declaration

+
  • +
    + + + + IDKeyPath + +
    +
    +
    +
    +
    +
    +

    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
    + +
    +
    +
    +
    +
  • @@ -850,13 +911,442 @@

    Declaration

  • +
    + +
    diff --git a/docs/Typealiases.html b/docs/Typealiases.html index 80971a4..a09ad74 100644 --- a/docs/Typealiases.html +++ b/docs/Typealiases.html @@ -475,7 +475,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes.html index 331e747..f9bcd01 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes.html @@ -282,7 +282,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/Database.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/Database.html index 90e8997..e57c354 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/Database.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/Database.html @@ -366,7 +366,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseDecoder.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseDecoder.html index 630771a..b87b7de 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseDecoder.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseDecoder.html @@ -181,7 +181,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseEncoder.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseEncoder.html index 9c81680..4ab0cdc 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseEncoder.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Classes/DatabaseEncoder.html @@ -181,7 +181,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions.html index 3a3f249..cefc5e2 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions.html @@ -175,7 +175,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions/RequestError.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions/RequestError.html index 57d3688..ac3958f 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions/RequestError.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Extensions/RequestError.html @@ -451,7 +451,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols.html index 675e8f1..93b9a0f 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols.html @@ -175,7 +175,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols/Model.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols/Model.html index 511b7e6..e43f774 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols/Model.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Protocols/Model.html @@ -251,6 +251,67 @@

    Declaration

    +
  • +
    + + + + IDKeyPath + +
    +
    +
    +
    +
    +
    +

    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
    + +
    +
    +
    +
    +
  • @@ -850,13 +911,442 @@

    Declaration

  • +
    +
      +
    • +
      + + + + executeQuery(query:parameters:using:_:) + + + Extension method + +
      +
      +
      +
      +
      +
      +

      Allows 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 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.

      +
      +
      +
      +
      +
      +
    • +
    • +
      + + + + executeQuery(query:parameters:using:_:) + + + Extension method + +
      +
      +
      +
      +
      +
      +

      Allows 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 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.

      +
      +
      +
      +
      +
      +
    • +
    • +
      + + + + executeQuery(query:parameters:using:_:) + + + Extension method + +
      +
      +
      +
      +
      +
      +

      Allows 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 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.

      +
      +
      +
      +
      +
      +
    • +
    • +
      + + + + executeQuery(query:parameters:using:_:) + + + Extension method + +
      +
      +
      +
      +
      +
      +

      Allows 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 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.

      +
      +
      +
      +
      +
      +
    • +
    • +
      + + + + executeQuery(query:parameters:using:_:) + + + Extension method + +
      +
      +
      +
      +
      +
      +

      Allows 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 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.

      +
      +
      +
      +
      +
      +
    • +
    +
    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Typealiases.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Typealiases.html index 80971a4..a09ad74 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Typealiases.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/Typealiases.html @@ -475,7 +475,7 @@

    Declaration

    diff --git a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/index.html b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/index.html index 0bff6fd..143bb2c 100644 --- a/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/index.html +++ b/docs/docsets/SwiftKueryORM.docset/Contents/Resources/Documents/index.html @@ -305,33 +305,158 @@

    Deleting

    ... }
    -

    Customization

    +

    Customizing your Model

    + +

    The ORM defines an extension to Model which provides a number of public static executeQuery(…) functions. These can be used to create custom functions within your model that perform more complex database operations. The example below defines a Person model and with a custom function that will retrieve all records which have age > 20:

    +
    // define the Person struct
    +struct Person: Codable {
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +}
     
    -

    The ORM uses Swift-Kuery which allows you to customize and execute your own queries without breaking any existing ORM functionality. You’ll want to have access to the table for your object, which you can get with the getTable() function:

    -
    do {
    -  let table = Grade.getTable()
    -} catch {
    -  // Error
    +// extend Person to conform to model and add overTwenties function
    +extension Person: Model {
    +
    +    // Define a synchronous function to retrieve all records of Person with age > 20
    +    public static func getOverTwenties() -> [Person]? {
    +        let wait = DispatchSemaphore(value: 0)
    +        // First get the table
    +        var table: Table
    +        do {
    +            table = try Person.getTable()
    +        } catch {
    +            // Handle error
    +        }
    +        // Define result, query and execute
    +        var overTwenties: [Person]? = nil
    +        let query = Select(from: table).where("age > 20")
    +
    +        Person.executeQuery(query: query, parameters: nil) { results, error in
    +            guard let results = results else {
    +                // Handle error
    +            }
    +            overTwenties = results
    +            wait.signal()
    +            return
    +        }
    +        wait.wait()
    +        return overTwenties
    +    }
     }
     
    -

    After you retrieve your table, you can create a Query object to specify what you want to execute on your database, and perform it like so:

    -
    executeQuery(query: Query) { (grade: Grade?, error: RequestError?) in
    -  ...
    +

    Alternatively you can define and asynchronous getOverTwenties function:

    +
    public static func getOverTwenties(oncompletion: @escaping ([Person]?, RequestError?)-> Void) {
    +    var table: Table
    +    do {
    +        table = try Person.getTable()
    +    } catch {
    +        // Handle error
    +    }
    +    let query = Select(from: table).where("age > 20")
    +    Person.executeQuery(query: query, parameters: nil, oncompletion)
     }
     
    -

    You can customize the parameters passed into your closure after you execute a Query like so:

    -
    executeQuery(query: Query) { grade, error in
    -  ...
    +

    which can be called in a fashion similar to the following:

    +
    Person.getOverTwenties() { result, error in
    +    guard let result = result else {
    +        // Handle error
    +    }
    +    // Use result
     }
    +
    -executeQuery(query: Query) { error in - ... +

    If you’d like to learn more about how you can customize queries, check out the Swift-Kuery repository for more information.

    +

    Model Identifiers

    + +

    The ORM has several options available for identifying an instance of a model.

    +

    Automatic ID assignment

    + +

    If you define your Model without specifying an ID property, either by using the idColumnName property or the default name of id, then the ORM will create an auto-incrementing column named id in the database table for the model, eg.

    +
    struct Person: Model {
    +    var firstname: String
    +    var surname: String
    +    var age: Int
     }
     
    -

    If you’d like to learn more about how you can customize queries, check out the Swift-Kuery repository for more information.

    +

    The model does not contain a property for the ID. The ORM provides a specific save API that will return the ID that was assigned. It is important to note the ORM will not link the returned ID to the instance of the Model in any way; you are responsible for maintaining this relationship if necessary. Below is an example of retrieving an ID for an instance of the Person model defined above:

    +
    let person = Person(firstname: "example", surname: "person", age: 21)
    +person.save() { (id: Int?, person, error) in
    +    guard let id = id, let person = person else{
    +        // Handle error
    +        return
    +    }
    +    // Use person and id
    +}
    +
    + +

    The compiler requires you to declare the type of the ID received by your completion handler; the type should be Int? for an ID that has been automatically assigned.

    +

    Manual ID assignment

    + +

    You can manage the assignment of IDs yourself by adding an id property to your model. You may customise the name of this property by defining idColumnName. For example:

    +
    struct Person: Model {
    +    var myIDField: Int
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +
    +    static var idColumnName = "myIDField"
    +    static var idColumnType = Int.self
    +}
    +
    + +

    When using a Model defined in this way, you are responsible for the assignment and management of IDs. Below is an example of saving an instance of the Person model defined above:

    +
    let person = Person(myIDField: 1, firstname: "example", surname: "person", age: 21)
    +person.save() { (person, error) in
    +    guard let person = person else {
    +        // Handle error
    +        return
    +    }
    +    // Use newly saved person
    +}
    +
    +

    Using optional ID properties

    + +

    Declaring your ID property as optional allows the ORM to assign the ID automatically when the model is saved. If the value of ID is nil, the database will assign an auto-incremented value. At present this is only support for an Int? type.

    + +

    You may instead provide an explicit value, which will be used instead of automatic assignment.

    + +

    Optional IDs must be identified by defining the idKeypath: IDKeyPath property, as in the example below:

    +
    struct Person: Model {
    +    var id: Int?
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +
    +    static var idKeypath: IDKeyPath = \Person.id
    +}
    +
    + +

    In the example above, the Model is defined with an ID property matching the default idColumnName value, but should you wish to use an alternative name you must define idColumnName accordingly.

    + +

    Below is an example of saving an instance of the Person defined above, both with an explicitly defined ID and without:

    +
    let person = Person(id: nil, firstname: Banana, surname: Man, age: 21)
    +let specificPerson = Person(id: 5, firstname: Super, surname: Ted, age: 26)
    +
    +person.save() { (savedPerson, error) in
    +        guard let newPerson = savedPerson else {
    +            // Handle error
    +        }
    +        print(newPerson.id) // Prints the next value in the databases identifier sequence, eg. 1
    +}
    +
    +specificPerson.save() { (savedPerson, error) in
    +        guard let newPerson = savedPerson else {
    +            // Handle error
    +        }
    +        print(newPerson.id) // Prints 5
    +}
    +
    + +

    NOTE - When using manual or optional ID properties, you should be prepared to handle violation of unique identifier constraints. These can occur if you attempt to save a model with an ID that already exists, or in the case of Postgres, if the auto-incremented value collides with an ID that was previously inserted explicitly.

    List of plugins

    -

    Customization

    +

    Customizing your Model

    + +

    The ORM defines an extension to Model which provides a number of public static executeQuery(…) functions. These can be used to create custom functions within your model that perform more complex database operations. The example below defines a Person model and with a custom function that will retrieve all records which have age > 20:

    +
    // define the Person struct
    +struct Person: Codable {
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +}
     
    -

    The ORM uses Swift-Kuery which allows you to customize and execute your own queries without breaking any existing ORM functionality. You’ll want to have access to the table for your object, which you can get with the getTable() function:

    -
    do {
    -  let table = Grade.getTable()
    -} catch {
    -  // Error
    +// extend Person to conform to model and add overTwenties function
    +extension Person: Model {
    +
    +    // Define a synchronous function to retrieve all records of Person with age > 20
    +    public static func getOverTwenties() -> [Person]? {
    +        let wait = DispatchSemaphore(value: 0)
    +        // First get the table
    +        var table: Table
    +        do {
    +            table = try Person.getTable()
    +        } catch {
    +            // Handle error
    +        }
    +        // Define result, query and execute
    +        var overTwenties: [Person]? = nil
    +        let query = Select(from: table).where("age > 20")
    +
    +        Person.executeQuery(query: query, parameters: nil) { results, error in
    +            guard let results = results else {
    +                // Handle error
    +            }
    +            overTwenties = results
    +            wait.signal()
    +            return
    +        }
    +        wait.wait()
    +        return overTwenties
    +    }
     }
     
    -

    After you retrieve your table, you can create a Query object to specify what you want to execute on your database, and perform it like so:

    -
    executeQuery(query: Query) { (grade: Grade?, error: RequestError?) in
    -  ...
    +

    Alternatively you can define and asynchronous getOverTwenties function:

    +
    public static func getOverTwenties(oncompletion: @escaping ([Person]?, RequestError?)-> Void) {
    +    var table: Table
    +    do {
    +        table = try Person.getTable()
    +    } catch {
    +        // Handle error
    +    }
    +    let query = Select(from: table).where("age > 20")
    +    Person.executeQuery(query: query, parameters: nil, oncompletion)
     }
     
    -

    You can customize the parameters passed into your closure after you execute a Query like so:

    -
    executeQuery(query: Query) { grade, error in
    -  ...
    +

    which can be called in a fashion similar to the following:

    +
    Person.getOverTwenties() { result, error in
    +    guard let result = result else {
    +        // Handle error
    +    }
    +    // Use result
     }
    +
    -executeQuery(query: Query) { error in - ... +

    If you’d like to learn more about how you can customize queries, check out the Swift-Kuery repository for more information.

    +

    Model Identifiers

    + +

    The ORM has several options available for identifying an instance of a model.

    +

    Automatic ID assignment

    + +

    If you define your Model without specifying an ID property, either by using the idColumnName property or the default name of id, then the ORM will create an auto-incrementing column named id in the database table for the model, eg.

    +
    struct Person: Model {
    +    var firstname: String
    +    var surname: String
    +    var age: Int
     }
     
    -

    If you’d like to learn more about how you can customize queries, check out the Swift-Kuery repository for more information.

    +

    The model does not contain a property for the ID. The ORM provides a specific save API that will return the ID that was assigned. It is important to note the ORM will not link the returned ID to the instance of the Model in any way; you are responsible for maintaining this relationship if necessary. Below is an example of retrieving an ID for an instance of the Person model defined above:

    +
    let person = Person(firstname: "example", surname: "person", age: 21)
    +person.save() { (id: Int?, person, error) in
    +    guard let id = id, let person = person else{
    +        // Handle error
    +        return
    +    }
    +    // Use person and id
    +}
    +
    + +

    The compiler requires you to declare the type of the ID received by your completion handler; the type should be Int? for an ID that has been automatically assigned.

    +

    Manual ID assignment

    + +

    You can manage the assignment of IDs yourself by adding an id property to your model. You may customise the name of this property by defining idColumnName. For example:

    +
    struct Person: Model {
    +    var myIDField: Int
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +
    +    static var idColumnName = "myIDField"
    +    static var idColumnType = Int.self
    +}
    +
    + +

    When using a Model defined in this way, you are responsible for the assignment and management of IDs. Below is an example of saving an instance of the Person model defined above:

    +
    let person = Person(myIDField: 1, firstname: "example", surname: "person", age: 21)
    +person.save() { (person, error) in
    +    guard let person = person else {
    +        // Handle error
    +        return
    +    }
    +    // Use newly saved person
    +}
    +
    +

    Using optional ID properties

    + +

    Declaring your ID property as optional allows the ORM to assign the ID automatically when the model is saved. If the value of ID is nil, the database will assign an auto-incremented value. At present this is only support for an Int? type.

    + +

    You may instead provide an explicit value, which will be used instead of automatic assignment.

    + +

    Optional IDs must be identified by defining the idKeypath: IDKeyPath property, as in the example below:

    +
    struct Person: Model {
    +    var id: Int?
    +    var firstname: String
    +    var surname: String
    +    var age: Int
    +
    +    static var idKeypath: IDKeyPath = \Person.id
    +}
    +
    + +

    In the example above, the Model is defined with an ID property matching the default idColumnName value, but should you wish to use an alternative name you must define idColumnName accordingly.

    + +

    Below is an example of saving an instance of the Person defined above, both with an explicitly defined ID and without:

    +
    let person = Person(id: nil, firstname: Banana, surname: Man, age: 21)
    +let specificPerson = Person(id: 5, firstname: Super, surname: Ted, age: 26)
    +
    +person.save() { (savedPerson, error) in
    +        guard let newPerson = savedPerson else {
    +            // Handle error
    +        }
    +        print(newPerson.id) // Prints the next value in the databases identifier sequence, eg. 1
    +}
    +
    +specificPerson.save() { (savedPerson, error) in
    +        guard let newPerson = savedPerson else {
    +            // Handle error
    +        }
    +        print(newPerson.id) // Prints 5
    +}
    +
    + +

    NOTE - When using manual or optional ID properties, you should be prepared to handle violation of unique identifier constraints. These can occur if you attempt to save a model with an ID that already exists, or in the case of Postgres, if the auto-incremented value collides with an ID that was previously inserted explicitly.

    List of plugins

      @@ -356,7 +481,7 @@

      License

      diff --git a/docs/search.json b/docs/search.json index 832748c..1e482b2 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -{"Typealiases.html#/s:13SwiftKueryORM21ConnectionPoolOptionsa":{"name":"ConnectionPoolOptions","abstract":"

      Defines the parameters of the ConnectionPool from SwiftKuery

      "},"Typealiases.html#/s:13SwiftKueryORM12RequestErrora":{"name":"RequestError","abstract":"

      Type Alias for RequestError from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM11SQLDataTypea":{"name":"SQLDataType","abstract":"

      Type Alias for SQLDataType from SwiftKuery

      "},"Typealiases.html#/s:13SwiftKueryORM11QueryParamsa":{"name":"QueryParams","abstract":"

      Public TypeAlias for QueryParams Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM11GreaterThana":{"name":"GreaterThan","abstract":"

      Public TypeAlias for GreaterThan Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM9LowerThana":{"name":"LowerThan","abstract":"

      Public TypeAlias for LowerThan Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM18GreaterThanOrEquala":{"name":"GreaterThanOrEqual","abstract":"

      Public TypeAlias for GreaterThanOrEqual Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM16LowerThanOrEquala":{"name":"LowerThanOrEqual","abstract":"

      Public TypeAlias for LowerThanOrEqual Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM14InclusiveRangea":{"name":"InclusiveRange","abstract":"

      Public TypeAlias for InclusiveRange Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM14ExclusiveRangea":{"name":"ExclusiveRange","abstract":"

      Public TypeAlias for ExclusiveRange Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM10Paginationa":{"name":"Pagination","abstract":"

      Public TypeAlias for Pagination Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM8Orderinga":{"name":"Ordering","abstract":"

      Public TypeAlias for Ordering Type from KituraContracts

      "},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9tableNameSSvpZ":{"name":"tableName","abstract":"

      Defines the tableName in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP12idColumnNameSSvpZ":{"name":"idColumnName","abstract":"

      Defines the id column name in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP12idColumnType0aB007SQLDataG0_pXpvpZ":{"name":"idColumnType","abstract":"

      Defines the id column type in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP15createTableSyncSbAA8DatabaseCSg5using_tKFZ":{"name":"createTableSync(using:)","abstract":"

      Call to create the table in the database synchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP11createTableyAA8DatabaseCSg5using_ySbSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"createTable(using:_:)","abstract":"

      Call to create the table in the database asynchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP13dropTableSyncSbAA8DatabaseCSg5using_tKFZ":{"name":"dropTableSync(using:)","abstract":"

      Call to drop the table in the database synchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9dropTableyAA8DatabaseCSg5using_ySbSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"dropTable(using:_:)","abstract":"

      Call to drop the table in the database asynchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4saveyAA8DatabaseCSg5using_yxSg_15KituraContracts12RequestErrorVSgtctF":{"name":"save(using:_:)","abstract":"

      Call to save a model to the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4saveyAA8DatabaseCSg5using_yqd__Sg_xSg15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lF":{"name":"save(using:_:)","abstract":"

      Call to save a model to the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP6updateyqd__2id_AA8DatabaseCSg5usingyxSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lF":{"name":"update(id:using:_:)","abstract":"

      Call to update a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP6deletey15KituraContracts10Identifier_p2id_AA8DatabaseCSg5usingyAE12RequestErrorVSgctFZ":{"name":"delete(id:using:_:)","abstract":"

      Call to delete a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9deleteAllyAA8DatabaseCSg5using_y15KituraContracts12RequestErrorVSgctFZ":{"name":"deleteAll(using:_:)","abstract":"

      Call to delete all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9deleteAllyAA8DatabaseCSg5using_qd__Sg8matchingy15KituraContracts12RequestErrorVSgctAK11QueryParamsRd__lFZ":{"name":"deleteAll(using:matching:_:)","abstract":"

      Call to delete all the models in the database mathcing the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP8getTable0aB00F0CyKFZ":{"name":"getTable()","abstract":"

      Call to get the table of the model

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4findyqd__2id_AA8DatabaseCSg5usingyxSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lFZ":{"name":"find(id:using:_:)","abstract":"

      Call to find a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ySayxGSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ySayqd___xtGSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ys10DictionaryVyqd__xGSg_15KituraContracts12RequestErrorVSgtctAM10IdentifierRd__s8HashableRd__lFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingySayxGSg_15KituraContracts12RequestErrorVSgtctAM11QueryParamsRd__lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingySayqd_0__xtGSg_15KituraContracts12RequestErrorVSgtctAM11QueryParamsRd__AM10IdentifierRd_0_r0_lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingys10DictionaryVyqd_0_xGSg_15KituraContracts12RequestErrorVSgtctAO11QueryParamsRd__AO10IdentifierRd_0_s8HashableRd_0_r0_lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html":{"name":"Model","abstract":"

      Protocol Model conforming to Codable defining the available operations

      "},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME25ormDatabaseNotInitializedACvpZ":{"name":"ormDatabaseNotInitialized","abstract":"

      Error when the Database has not been set

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME016ormTableCreationD0ACvpZ":{"name":"ormTableCreationError","abstract":"

      Error when the createTable call fails

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME018ormCodableDecodingD0ACvpZ":{"name":"ormCodableDecodingError","abstract":"

      Error when the TypeDecoder failed to extract the types from the model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME019ormDatabaseDecodingD0ACvpZ":{"name":"ormDatabaseDecodingError","abstract":"

      Error when the DatabaseDecoder could not construct a Model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME019ormDatabaseEncodingD0ACvpZ":{"name":"ormDatabaseEncodingError","abstract":"

      Error when the DatabaseEncoder could not decode a Model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME08ormQueryD0ACvpZ":{"name":"ormQueryError","abstract":"

      Error when the Query fails to be executed

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME11ormNotFoundACvpZ":{"name":"ormNotFound","abstract":"

      Error when the values retrieved from the database are nil

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME25ormInvalidTableDefinitionACvpZ":{"name":"ormInvalidTableDefinition","abstract":"

      Error when the table defined does not contain a specific column

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME013ormIdentifierD0ACvpZ":{"name":"ormIdentifierError","abstract":"

      Error when the Identifier could not be constructed

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME011ormInternalD0ACvpZ":{"name":"ormInternalError","abstract":"

      Error when an internal error occurs

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME19ormConnectionFailedACvpZ":{"name":"ormConnectionFailed","abstract":"

      Error when retrieving a connection from the database fails

      ","parent_name":"RequestError"},"Extensions/RequestError.html":{"name":"RequestError","abstract":"

      Extension of the RequestError from KituraContracts

      "},"Classes/DatabaseEncoder.html#/s:13SwiftKueryORM15DatabaseEncoderC6encodes10DictionaryVySSypGxKs9EncodableRzlF":{"name":"encode(_:)","abstract":"

      Encode a Encodable type to a dictionary [String: Any]

      ","parent_name":"DatabaseEncoder"},"Classes/DatabaseDecoder.html#/s:13SwiftKueryORM15DatabaseDecoderC6decodexxm_s10DictionaryVySSypSgGtKs9DecodableRzlF":{"name":"decode(_:_:)","abstract":"

      Decode from a dictionary [String: Any] to a Decodable type

      ","parent_name":"DatabaseDecoder"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC0D4Taska":{"name":"DatabaseTask","abstract":"

      Definition of a DatabaseTask completion handler which accepts an optional Connection and optional Error

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC7defaultACSgvpZ":{"name":"default","abstract":"

      Global default Database for the application

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC9tableInfoAA05TableF0CvpZ":{"name":"tableInfo","abstract":"

      Instance of TableInfo containing cached tables

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCAC0aB010Connection_p6single_tcfc":{"name":"init(single:)","abstract":"

      Create a Database instance which uses a single connection to perform each operation. The connection will remain open for the lifetime of the Database.","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCAC0aB014ConnectionPoolCcfc":{"name":"init(_:)","abstract":"

      Create a Database instance with multiple connections, managed by a connection pool, allowing operations to be performed concurrently. These connections will remain open for the lifetime of the Database.","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCACyy0aB010Connection_pSg_AD10QueryErrorOSgtcc9generator_tcfc":{"name":"init(generator:)","abstract":"

      Create a Database instance which uses short-lived connections that are generated on demand. A new Connection is created for every operation, and will be closed once the operation completes.","parent_name":"Database"},"Classes/Database.html":{"name":"Database","abstract":"

      Class defining the connection to the database.

      "},"Classes/DatabaseDecoder.html":{"name":"DatabaseDecoder","abstract":"

      Class used to construct a Model from a row in the database

      "},"Classes/DatabaseEncoder.html":{"name":"DatabaseEncoder","abstract":"

      Class used to construct a dictionary [String: Any] from a Model

      "},"Classes.html#/s:13SwiftKueryORM9TableInfoC":{"name":"TableInfo","abstract":"

      Class caching the tables for the models of the application

      "},"Classes.html":{"name":"Classes","abstract":"

      The following classes are available globally.

      "},"Extensions.html":{"name":"Extensions","abstract":"

      The following extensions are available globally.

      "},"Protocols.html":{"name":"Protocols","abstract":"

      The following protocols are available globally.

      "},"Typealiases.html":{"name":"Type Aliases","abstract":"

      The following type aliases are available globally.

      "}} \ No newline at end of file +{"Typealiases.html#/s:13SwiftKueryORM21ConnectionPoolOptionsa":{"name":"ConnectionPoolOptions","abstract":"

      Defines the parameters of the ConnectionPool from SwiftKuery

      "},"Typealiases.html#/s:13SwiftKueryORM12RequestErrora":{"name":"RequestError","abstract":"

      Type Alias for RequestError from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM11SQLDataTypea":{"name":"SQLDataType","abstract":"

      Type Alias for SQLDataType from SwiftKuery

      "},"Typealiases.html#/s:13SwiftKueryORM11QueryParamsa":{"name":"QueryParams","abstract":"

      Public TypeAlias for QueryParams Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM11GreaterThana":{"name":"GreaterThan","abstract":"

      Public TypeAlias for GreaterThan Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM9LowerThana":{"name":"LowerThan","abstract":"

      Public TypeAlias for LowerThan Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM18GreaterThanOrEquala":{"name":"GreaterThanOrEqual","abstract":"

      Public TypeAlias for GreaterThanOrEqual Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM16LowerThanOrEquala":{"name":"LowerThanOrEqual","abstract":"

      Public TypeAlias for LowerThanOrEqual Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM14InclusiveRangea":{"name":"InclusiveRange","abstract":"

      Public TypeAlias for InclusiveRange Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM14ExclusiveRangea":{"name":"ExclusiveRange","abstract":"

      Public TypeAlias for ExclusiveRange Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM10Paginationa":{"name":"Pagination","abstract":"

      Public TypeAlias for Pagination Type from KituraContracts

      "},"Typealiases.html#/s:13SwiftKueryORM8Orderinga":{"name":"Ordering","abstract":"

      Public TypeAlias for Ordering Type from KituraContracts

      "},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9tableNameSSvpZ":{"name":"tableName","abstract":"

      Defines the tableName in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP12idColumnNameSSvpZ":{"name":"idColumnName","abstract":"

      Defines the id column name in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP12idColumnType0aB007SQLDataG0_pXpvpZ":{"name":"idColumnType","abstract":"

      Defines the id column type in the Database

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9IDKeyPatha":{"name":"IDKeyPath","abstract":"

      Defines typealias for the id fields keypath

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9idKeypaths15WritableKeyPathCyxSiSgGSgvpZ":{"name":"idKeypath","abstract":"

      Defines the keypath to the Models id field

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP15createTableSyncSbAA8DatabaseCSg5using_tKFZ":{"name":"createTableSync(using:)","abstract":"

      Call to create the table in the database synchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP11createTableyAA8DatabaseCSg5using_ySbSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"createTable(using:_:)","abstract":"

      Call to create the table in the database asynchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP13dropTableSyncSbAA8DatabaseCSg5using_tKFZ":{"name":"dropTableSync(using:)","abstract":"

      Call to drop the table in the database synchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9dropTableyAA8DatabaseCSg5using_ySbSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"dropTable(using:_:)","abstract":"

      Call to drop the table in the database asynchronously

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4saveyAA8DatabaseCSg5using_yxSg_15KituraContracts12RequestErrorVSgtctF":{"name":"save(using:_:)","abstract":"

      Call to save a model to the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4saveyAA8DatabaseCSg5using_yqd__Sg_xSg15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lF":{"name":"save(using:_:)","abstract":"

      Call to save a model to the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP6updateyqd__2id_AA8DatabaseCSg5usingyxSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lF":{"name":"update(id:using:_:)","abstract":"

      Call to update a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP6deletey15KituraContracts10Identifier_p2id_AA8DatabaseCSg5usingyAE12RequestErrorVSgctFZ":{"name":"delete(id:using:_:)","abstract":"

      Call to delete a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9deleteAllyAA8DatabaseCSg5using_y15KituraContracts12RequestErrorVSgctFZ":{"name":"deleteAll(using:_:)","abstract":"

      Call to delete all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP9deleteAllyAA8DatabaseCSg5using_qd__Sg8matchingy15KituraContracts12RequestErrorVSgctAK11QueryParamsRd__lFZ":{"name":"deleteAll(using:matching:_:)","abstract":"

      Call to delete all the models in the database mathcing the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP8getTable0aB00F0CyKFZ":{"name":"getTable()","abstract":"

      Call to get the table of the model

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP4findyqd__2id_AA8DatabaseCSg5usingyxSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lFZ":{"name":"find(id:using:_:)","abstract":"

      Call to find a model in the database with an id that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ySayxGSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ySayqd___xtGSg_15KituraContracts12RequestErrorVSgtctAK10IdentifierRd__lFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_ys10DictionaryVyqd__xGSg_15KituraContracts12RequestErrorVSgtctAM10IdentifierRd__s8HashableRd__lFZ":{"name":"findAll(using:_:)","abstract":"

      Call to find all the models in the database that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingySayxGSg_15KituraContracts12RequestErrorVSgtctAM11QueryParamsRd__lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingySayqd_0__xtGSg_15KituraContracts12RequestErrorVSgtctAM11QueryParamsRd__AM10IdentifierRd_0_r0_lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelP7findAllyAA8DatabaseCSg5using_qd__Sg8matchingys10DictionaryVyqd_0_xGSg_15KituraContracts12RequestErrorVSgtctAO11QueryParamsRd__AO10IdentifierRd_0_s8HashableRd_0_r0_lFZ":{"name":"findAll(using:matching:_:)","abstract":"

      Call to find all the models in the database matching the QueryParams that accepts a completion","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelPAAE12executeQueryy0aB00F0_p5query_SayypSgG10parametersAA8DatabaseCSg5usingyxSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"executeQuery(query:parameters:using:_:)","abstract":"

      Allows custom functions on a model to query the database directly.

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelPAAE12executeQueryy0aB00F0_p5query_SayypSgG10parametersAA8DatabaseCSg5usingyqd__Sg_xSg15KituraContracts12RequestErrorVSgtctAQ10IdentifierRd__lFZ":{"name":"executeQuery(query:parameters:using:_:)","abstract":"

      Allows custom functions on a model to query the database directly.

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelPAAE12executeQueryy0aB00F0_p5query_SayypSgGSg10parametersAA8DatabaseCSg5usingySayxGSg_15KituraContracts12RequestErrorVSgtctFZ":{"name":"executeQuery(query:parameters:using:_:)","abstract":"

      Allows custom functions on a model to query the database directly.

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelPAAE12executeQueryy0aB00F0_p5query_SayypSgGSg10parametersAA8DatabaseCSg5usingySayqd___xtGSg_15KituraContracts12RequestErrorVSgtctAR10IdentifierRd__lFZ":{"name":"executeQuery(query:parameters:using:_:)","abstract":"

      Allows custom functions on a model to query the database directly.

      ","parent_name":"Model"},"Protocols/Model.html#/s:13SwiftKueryORM5ModelPAAE12executeQueryy0aB00F0_p5query_SayypSgGSg10parametersAA8DatabaseCSg5usingy15KituraContracts12RequestErrorVSgctFZ":{"name":"executeQuery(query:parameters:using:_:)","abstract":"

      Allows custom functions on a model to query the database directly.

      ","parent_name":"Model"},"Protocols/Model.html":{"name":"Model","abstract":"

      Protocol Model conforming to Codable defining the available operations

      "},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME25ormDatabaseNotInitializedACvpZ":{"name":"ormDatabaseNotInitialized","abstract":"

      Error when the Database has not been set

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME016ormTableCreationD0ACvpZ":{"name":"ormTableCreationError","abstract":"

      Error when the createTable call fails

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME018ormCodableDecodingD0ACvpZ":{"name":"ormCodableDecodingError","abstract":"

      Error when the TypeDecoder failed to extract the types from the model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME019ormDatabaseDecodingD0ACvpZ":{"name":"ormDatabaseDecodingError","abstract":"

      Error when the DatabaseDecoder could not construct a Model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME019ormDatabaseEncodingD0ACvpZ":{"name":"ormDatabaseEncodingError","abstract":"

      Error when the DatabaseEncoder could not decode a Model

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME08ormQueryD0ACvpZ":{"name":"ormQueryError","abstract":"

      Error when the Query fails to be executed

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME11ormNotFoundACvpZ":{"name":"ormNotFound","abstract":"

      Error when the values retrieved from the database are nil

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME25ormInvalidTableDefinitionACvpZ":{"name":"ormInvalidTableDefinition","abstract":"

      Error when the table defined does not contain a specific column

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME013ormIdentifierD0ACvpZ":{"name":"ormIdentifierError","abstract":"

      Error when the Identifier could not be constructed

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME011ormInternalD0ACvpZ":{"name":"ormInternalError","abstract":"

      Error when an internal error occurs

      ","parent_name":"RequestError"},"Extensions/RequestError.html#/s:15KituraContracts12RequestErrorV13SwiftKueryORME19ormConnectionFailedACvpZ":{"name":"ormConnectionFailed","abstract":"

      Error when retrieving a connection from the database fails

      ","parent_name":"RequestError"},"Extensions/RequestError.html":{"name":"RequestError","abstract":"

      Extension of the RequestError from KituraContracts

      "},"Classes/DatabaseEncoder.html#/s:13SwiftKueryORM15DatabaseEncoderC6encodes10DictionaryVySSypGxKs9EncodableRzlF":{"name":"encode(_:)","abstract":"

      Encode a Encodable type to a dictionary [String: Any]

      ","parent_name":"DatabaseEncoder"},"Classes/DatabaseDecoder.html#/s:13SwiftKueryORM15DatabaseDecoderC6decodexxm_s10DictionaryVySSypSgGtKs9DecodableRzlF":{"name":"decode(_:_:)","abstract":"

      Decode from a dictionary [String: Any] to a Decodable type

      ","parent_name":"DatabaseDecoder"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC0D4Taska":{"name":"DatabaseTask","abstract":"

      Definition of a DatabaseTask completion handler which accepts an optional Connection and optional Error

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC7defaultACSgvpZ":{"name":"default","abstract":"

      Global default Database for the application

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseC9tableInfoAA05TableF0CvpZ":{"name":"tableInfo","abstract":"

      Instance of TableInfo containing cached tables

      ","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCAC0aB010Connection_p6single_tcfc":{"name":"init(single:)","abstract":"

      Create a Database instance which uses a single connection to perform each operation. The connection will remain open for the lifetime of the Database.","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCAC0aB014ConnectionPoolCcfc":{"name":"init(_:)","abstract":"

      Create a Database instance with multiple connections, managed by a connection pool, allowing operations to be performed concurrently. These connections will remain open for the lifetime of the Database.","parent_name":"Database"},"Classes/Database.html#/s:13SwiftKueryORM8DatabaseCACyy0aB010Connection_pSg_AD10QueryErrorOSgtcc9generator_tcfc":{"name":"init(generator:)","abstract":"

      Create a Database instance which uses short-lived connections that are generated on demand. A new Connection is created for every operation, and will be closed once the operation completes.","parent_name":"Database"},"Classes/Database.html":{"name":"Database","abstract":"

      Class defining the connection to the database.

      "},"Classes/DatabaseDecoder.html":{"name":"DatabaseDecoder","abstract":"

      Class used to construct a Model from a row in the database

      "},"Classes/DatabaseEncoder.html":{"name":"DatabaseEncoder","abstract":"

      Class used to construct a dictionary [String: Any] from a Model

      "},"Classes.html#/s:13SwiftKueryORM9TableInfoC":{"name":"TableInfo","abstract":"

      Class caching the tables for the models of the application

      "},"Classes.html":{"name":"Classes","abstract":"

      The following classes are available globally.

      "},"Extensions.html":{"name":"Extensions","abstract":"

      The following extensions are available globally.

      "},"Protocols.html":{"name":"Protocols","abstract":"

      The following protocols are available globally.

      "},"Typealiases.html":{"name":"Type Aliases","abstract":"

      The following type aliases are available globally.

      "}} \ No newline at end of file diff --git a/docs/undocumented.json b/docs/undocumented.json index 74a3ab2..0fa4bec 100644 --- a/docs/undocumented.json +++ b/docs/undocumented.json @@ -2,14 +2,14 @@ "warnings": [ { "file": "/Users/travis/build/IBM-Swift/Swift-Kuery-ORM/Sources/SwiftKueryORM/Model.swift", - "line": 223, + "line": 231, "symbol": "Model.save(using:_:)", "symbol_kind": "source.lang.swift.decl.function.method.instance", "warning": "undocumented" }, { "file": "/Users/travis/build/IBM-Swift/Swift-Kuery-ORM/Sources/SwiftKueryORM/Model.swift", - "line": 241, + "line": 250, "symbol": "Model.save(using:_:)", "symbol_kind": "source.lang.swift.decl.function.method.instance", "warning": "undocumented"