From 51ee0a78954d2ea03dc996d08e0128e802bc1ea3 Mon Sep 17 00:00:00 2001 From: nick Date: Sun, 1 Dec 2019 02:55:10 +0800 Subject: [PATCH 1/4] Add defaultDatabase property in Protocol Model --- Sources/SwiftKueryORM/Model.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftKueryORM/Model.swift b/Sources/SwiftKueryORM/Model.swift index de11b21..98b7663 100644 --- a/Sources/SwiftKueryORM/Model.swift +++ b/Sources/SwiftKueryORM/Model.swift @@ -33,6 +33,9 @@ public enum DateEncodingFormat { /// Protocol Model conforming to Codable defining the available operations public protocol Model: Codable { + /// Defines the default using database + static var defaultDatabase: Database? { get } + /// Defines the tableName in the Database static var tableName: String {get} /// Defines the id column name in the Database @@ -119,6 +122,9 @@ public protocol Model: Codable { } public extension Model { + /// Defaults to Database.default + static var defaultDatabase: Database? { return Database.default } + /// Defaults to the name of the model + "s" static var tableName: String { let structName = String(describing: self) @@ -138,7 +144,7 @@ public extension Model { static var dateEncodingFormat: DateEncodingFormat { return .double } private static func executeTask(using db: Database? = nil, task: @escaping ((Connection?, QueryError?) -> ())) { - guard let database = db ?? Database.default else { + guard let database = db ?? defaultDatabase else { return task(nil, QueryError.databaseError("ORM database not initialised")) } From c6684851c631343621e0a5d4cf9dfb1ac47d4b6c Mon Sep 17 00:00:00 2001 From: nick Date: Mon, 9 Dec 2019 15:50:14 +0800 Subject: [PATCH 2/4] add static func using defaultDatabase --- Sources/SwiftKueryORM/Model.swift | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/SwiftKueryORM/Model.swift b/Sources/SwiftKueryORM/Model.swift index 98b7663..bda286d 100644 --- a/Sources/SwiftKueryORM/Model.swift +++ b/Sources/SwiftKueryORM/Model.swift @@ -143,7 +143,7 @@ public extension Model { static var dateEncodingFormat: DateEncodingFormat { return .double } - private static func executeTask(using db: Database? = nil, task: @escaping ((Connection?, QueryError?) -> ())) { + private static func executeTask(using db: Database? = defaultDatabase, task: @escaping ((Connection?, QueryError?) -> ())) { guard let database = db ?? defaultDatabase else { return task(nil, QueryError.databaseError("ORM database not initialised")) @@ -152,7 +152,7 @@ public extension Model { } @discardableResult - static func createTableSync(using db: Database? = nil) throws -> Bool { + static func createTableSync(using db: Database? = defaultDatabase) throws -> Bool { var result: Bool? var error: RequestError? let semaphore = DispatchSemaphore(value: 0) @@ -173,7 +173,7 @@ public extension Model { return resultUnwrapped } - static func createTable(using db: Database? = nil, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { + static func createTable(using db: Database? = defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -202,7 +202,7 @@ public extension Model { } @discardableResult - static func dropTableSync(using db: Database? = nil) throws -> Bool { + static func dropTableSync(using db: Database? = defaultDatabase) throws -> Bool { var result: Bool? var error: RequestError? let semaphore = DispatchSemaphore(value: 0) @@ -223,7 +223,7 @@ public extension Model { return resultUnwrapped } - static func dropTable(using db : Database? = nil, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { + static func dropTable(using db : Database? = defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -251,7 +251,7 @@ public extension Model { } } - func save(using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + func save(using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table var values: [String : Any] do { @@ -270,7 +270,7 @@ public extension Model { self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - func save(using db: Database? = nil, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) { + func save(using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) { var table: Table var values: [String : Any] do { @@ -288,7 +288,7 @@ public extension Model { self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - func update(id: I, using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + func update(id: I, using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table var values: [String: Any] do { @@ -312,7 +312,7 @@ public extension Model { executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - static func delete(id: Identifier, using db: Database? = nil, _ onCompletion: @escaping (RequestError?) -> Void) { + static func delete(id: Identifier, using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -331,7 +331,7 @@ public extension Model { Self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - static func deleteAll(using db: Database? = nil, _ onCompletion: @escaping (RequestError?) -> Void) { + static func deleteAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -347,7 +347,7 @@ public extension Model { /// Delete all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: An optional RequestError - static func deleteAll(using db: Database? = nil, matching queryParams: Q?, _ onCompletion: @escaping (RequestError?) -> Void) { + static func deleteAll(using db: Database? = defaultDatabase, matching queryParams: Q?, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -381,7 +381,7 @@ public extension Model { Self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - private func executeQuery(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { + private func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { var dictionaryTitleToValue = [String: Any?]() Self.executeTask(using: db) { connection, error in guard let connection = connection else { @@ -440,7 +440,7 @@ public extension Model { } } - private func executeQuery(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { + private func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -495,7 +495,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -540,7 +540,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?], using db: Database? = nil, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -603,7 +603,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping ([Self]?, RequestError?)-> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?)-> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -668,7 +668,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -747,7 +747,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = nil, _ onCompletion: @escaping (RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -978,7 +978,7 @@ public extension Model { /// Find a model with an id /// - Parameter using: Optional Database to use /// - Returns: A tuple (Model, RequestError) - static func find(id: I, using db: Database? = nil, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + static func find(id: I, using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -999,7 +999,7 @@ public extension Model { /// - static func findAll(using db: Database? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1015,7 +1015,7 @@ public extension Model { /// Find all the models /// - Parameter using: Optional Database to use /// - Returns: An array of tuples (id, model) - static func findAll(using db: Database? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1029,7 +1029,7 @@ public extension Model { } /// :nodoc: - static func findAll(using db: Database? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1058,7 +1058,7 @@ public extension Model { /// - Parameter matching: Optional QueryParams to use /// - Returns: An array of model - static func findAll(using db: Database? = nil, matching queryParams: Q? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1083,7 +1083,7 @@ public extension Model { /// Find all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: An array of tuples (id, model) - static func findAll(using db: Database? = nil, matching queryParams: Q? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1108,7 +1108,7 @@ public extension Model { /// Find all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: A dictionary [id: model] - static func findAll(using db: Database? = nil, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() From 4c330d56d7c1eb08cd7f4e6cbec025284e9e4707 Mon Sep 17 00:00:00 2001 From: nick Date: Mon, 9 Dec 2019 23:09:33 +0800 Subject: [PATCH 3/4] fix for Swift 4.0.3 --- Sources/SwiftKueryORM/Model.swift | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/SwiftKueryORM/Model.swift b/Sources/SwiftKueryORM/Model.swift index bda286d..07eec8e 100644 --- a/Sources/SwiftKueryORM/Model.swift +++ b/Sources/SwiftKueryORM/Model.swift @@ -143,7 +143,7 @@ public extension Model { static var dateEncodingFormat: DateEncodingFormat { return .double } - private static func executeTask(using db: Database? = defaultDatabase, task: @escaping ((Connection?, QueryError?) -> ())) { + private static func executeTask(using db: Database? = Self.defaultDatabase, task: @escaping ((Connection?, QueryError?) -> ())) { guard let database = db ?? defaultDatabase else { return task(nil, QueryError.databaseError("ORM database not initialised")) @@ -152,7 +152,7 @@ public extension Model { } @discardableResult - static func createTableSync(using db: Database? = defaultDatabase) throws -> Bool { + static func createTableSync(using db: Database? = Self.defaultDatabase) throws -> Bool { var result: Bool? var error: RequestError? let semaphore = DispatchSemaphore(value: 0) @@ -173,7 +173,7 @@ public extension Model { return resultUnwrapped } - static func createTable(using db: Database? = defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { + static func createTable(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -202,7 +202,7 @@ public extension Model { } @discardableResult - static func dropTableSync(using db: Database? = defaultDatabase) throws -> Bool { + static func dropTableSync(using db: Database? = Self.defaultDatabase) throws -> Bool { var result: Bool? var error: RequestError? let semaphore = DispatchSemaphore(value: 0) @@ -223,7 +223,7 @@ public extension Model { return resultUnwrapped } - static func dropTable(using db : Database? = defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { + static func dropTable(using db : Database? = Self.defaultDatabase, _ onCompletion: @escaping (Bool?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -251,7 +251,7 @@ public extension Model { } } - func save(using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + func save(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table var values: [String : Any] do { @@ -270,7 +270,7 @@ public extension Model { self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - func save(using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) { + func save(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void) { var table: Table var values: [String : Any] do { @@ -288,7 +288,7 @@ public extension Model { self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - func update(id: I, using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + func update(id: I, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table var values: [String: Any] do { @@ -312,7 +312,7 @@ public extension Model { executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - static func delete(id: Identifier, using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { + static func delete(id: Identifier, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -331,7 +331,7 @@ public extension Model { Self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - static func deleteAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { + static func deleteAll(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -347,7 +347,7 @@ public extension Model { /// Delete all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: An optional RequestError - static func deleteAll(using db: Database? = defaultDatabase, matching queryParams: Q?, _ onCompletion: @escaping (RequestError?) -> Void) { + static func deleteAll(using db: Database? = Self.defaultDatabase, matching queryParams: Q?, _ onCompletion: @escaping (RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -381,7 +381,7 @@ public extension Model { Self.executeQuery(query: query, parameters: parameters, using: db, onCompletion) } - private func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { + private func executeQuery(query: Query, parameters: [Any?], using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { var dictionaryTitleToValue = [String: Any?]() Self.executeTask(using: db) { connection, error in guard let connection = connection else { @@ -440,7 +440,7 @@ public extension Model { } } - private func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { + private func executeQuery(query: Query, parameters: [Any?], using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -495,7 +495,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?], using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -540,7 +540,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?], using db: Database? = defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?], using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (I?, Self?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -603,7 +603,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?)-> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?)-> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -668,7 +668,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -747,7 +747,7 @@ public extension Model { /// - Parameter parameters: An optional array of parameters to pass to the query /// - Parameter using: Optional Database to use /// - Parameter 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. - static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void ) { + static func executeQuery(query: Query, parameters: [Any?]? = nil, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (RequestError?) -> Void ) { Self.executeTask(using: db) { connection, error in guard let connection = connection else { guard let error = error else { @@ -978,7 +978,7 @@ public extension Model { /// Find a model with an id /// - Parameter using: Optional Database to use /// - Returns: A tuple (Model, RequestError) - static func find(id: I, using db: Database? = defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { + static func find(id: I, using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping (Self?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -999,7 +999,7 @@ public extension Model { /// - static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1015,7 +1015,7 @@ public extension Model { /// Find all the models /// - Parameter using: Optional Database to use /// - Returns: An array of tuples (id, model) - static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1029,7 +1029,7 @@ public extension Model { } /// :nodoc: - static func findAll(using db: Database? = defaultDatabase, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1058,7 +1058,7 @@ public extension Model { /// - Parameter matching: Optional QueryParams to use /// - Returns: An array of model - static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1083,7 +1083,7 @@ public extension Model { /// Find all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: An array of tuples (id, model) - static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([(I, Self)]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() @@ -1108,7 +1108,7 @@ public extension Model { /// Find all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: A dictionary [id: model] - static func findAll(using db: Database? = defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.sdefaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable() From d9b9cd94d4425fb2adf9138f8020ea352d89d62f Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 10 Dec 2019 08:13:53 +0800 Subject: [PATCH 4/4] fix typo --- Sources/SwiftKueryORM/Model.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftKueryORM/Model.swift b/Sources/SwiftKueryORM/Model.swift index 07eec8e..dcf63ad 100644 --- a/Sources/SwiftKueryORM/Model.swift +++ b/Sources/SwiftKueryORM/Model.swift @@ -1108,7 +1108,7 @@ public extension Model { /// Find all the models matching the QueryParams /// - Parameter using: Optional Database to use /// - Returns: A dictionary [id: model] - static func findAll(using db: Database? = Self.sdefaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { + static func findAll(using db: Database? = Self.defaultDatabase, matching queryParams: Q? = nil, _ onCompletion: @escaping ([I: Self]?, RequestError?) -> Void) { var table: Table do { table = try Self.getTable()