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"])
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])]