From be74f3ea24e591390915c6fa1126451645ec1bc5 Mon Sep 17 00:00:00 2001 From: Rockford Wei Date: Fri, 25 Sep 2020 15:46:24 -0400 Subject: [PATCH 1/2] allowing asynchonizational query --- Sources/PerfectCRUD/Database.swift | 17 +++++++++++++++++ Sources/PerfectCRUD/PerfectCRUD.swift | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/Sources/PerfectCRUD/Database.swift b/Sources/PerfectCRUD/Database.swift index 94f42a7..f607f2c 100644 --- a/Sources/PerfectCRUD/Database.swift +++ b/Sources/PerfectCRUD/Database.swift @@ -36,6 +36,23 @@ public extension Database { } return ret } + func asyncSql(_ sql: String, bindings: Bindings = [], _ type: A.Type, completion: @escaping ([A], Error?) -> ()) throws { + CRUDLogging.log(.query, sql) + let delegate = try configuration.sqlExeDelegate(forSQL: sql) + try delegate.bind(bindings, skip: 0) + delegate.asyncExecute { delegate in + var ret: [A] = [] + do { + while try delegate.hasNext() { + let rowDecoder: CRUDRowDecoder = CRUDRowDecoder(delegate: delegate) + ret.append(try A(from: rowDecoder)) + } + completion(ret, nil) + } catch { + completion(ret, error) + } + } + } } public extension Database { diff --git a/Sources/PerfectCRUD/PerfectCRUD.swift b/Sources/PerfectCRUD/PerfectCRUD.swift index d71a3f8..fb7e936 100644 --- a/Sources/PerfectCRUD/PerfectCRUD.swift +++ b/Sources/PerfectCRUD/PerfectCRUD.swift @@ -53,6 +53,7 @@ public protocol SQLExeDelegate { func bind(_ bindings: Bindings, skip: Int) throws func hasNext() throws -> Bool func next() throws -> KeyedDecodingContainer? + func asyncExecute(completion: @escaping (SQLExeDelegate) -> ()) } public protocol DatabaseConfigurationProtocol { @@ -252,6 +253,10 @@ struct PivotContainer { } struct SQLTopExeDelegate: SQLExeDelegate { + func asyncExecute(completion: @escaping (SQLExeDelegate) -> ()) { + // place holder + } + let genState: SQLGenState let master: (table: SQLGenState.TableData, delegate: SQLExeDelegate) let subObjects: [String:(onKeyName: String, onKey: AnyKeyPath, equalsKey: AnyKeyPath, objects: [Any])] From 12277a5aa917a58352b7906d92b5d25f42629365 Mon Sep 17 00:00:00 2001 From: Rockford Wei Date: Sat, 2 Apr 2022 09:23:06 -0400 Subject: [PATCH 2/2] adding iOS support --- .../xcode/package.xcworkspace/contents.xcworkspacedata | 7 +++++++ Package.swift | 1 + 2 files changed, 8 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.swift b/Package.swift index be10ce6..dfb882c 100644 --- a/Package.swift +++ b/Package.swift @@ -7,6 +7,7 @@ let package = Package( name: "PerfectCRUD", platforms: [ .macOS(.v10_15), + .iOS(.v10) ], products: [ .library(name: "PerfectCRUD", targets: ["PerfectCRUD"])