Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add iOS support #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let package = Package(
name: "PerfectCRUD",
platforms: [
.macOS(.v10_15),
.iOS(.v10)
],
products: [
.library(name: "PerfectCRUD", targets: ["PerfectCRUD"])
Expand Down
17 changes: 17 additions & 0 deletions Sources/PerfectCRUD/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public extension Database {
}
return ret
}
func asyncSql<A: Codable>(_ 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<ColumnKey> = CRUDRowDecoder(delegate: delegate)
ret.append(try A(from: rowDecoder))
}
completion(ret, nil)
} catch {
completion(ret, error)
}
}
}
}

public extension Database {
Expand Down
5 changes: 5 additions & 0 deletions Sources/PerfectCRUD/PerfectCRUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public protocol SQLExeDelegate {
func bind(_ bindings: Bindings, skip: Int) throws
func hasNext() throws -> Bool
func next<A: CodingKey>() throws -> KeyedDecodingContainer<A>?
func asyncExecute(completion: @escaping (SQLExeDelegate) -> ())
}

public protocol DatabaseConfigurationProtocol {
Expand Down Expand Up @@ -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])]
Expand Down