Created
June 20, 2018 11:35
-
-
Save MrMage/b06e5522bb7e020bfc5998d20f9483b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import FluentPostgreSQL | |
extension QueryBuilder where Result: Model, | |
Result.Database == Database, | |
Database.Query: FluentSQLQuery, | |
Database.QueryField: SQLColumnIdentifier, | |
Database.QueryField: Hashable, | |
Database.QueryData == Dictionary<String, Database.Query.Expression> { | |
public func update<T>(_ keyPath: WritableKeyPath<Result, T>, to value: T) -> Future<Void> where T: Encodable { | |
Database.queryDataSet(Database.queryField(.keyPath(keyPath)), to: value, on: &query) | |
return run(Database.queryActionUpdate) | |
} | |
public func update(_ data: [Database.QueryField: Database.Query.Expression.Bind]) -> Future<Void> { | |
var values: Database.QueryData = [:] | |
for (field, value) in data { | |
values[field.identifier.string] = .bind(value) | |
} | |
Database.queryDataApply(values, to: &query) | |
return run(Database.queryActionUpdate) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment