-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major overhaul of the entire SQLKit package (#172)
* Bump Swift to 5.8, add Dependabot config * Docs overhaul * Deprecate \(raw:) in SQLQueryString with rename to explicitly "unsafe" version, numerous other SQLQueryString cleanups * ExistentialAny compliance * Overhaul SQLRowDecoder and SQLQueryEncoder * NIO -> NIOCore in imports * Fix all Sendable complaints from the compiler * Make SQLDatabaseReportedVersion Comparable * Deprecate SQLError and SQLErrorType, deprecate use of binds in SQLRaw. * Improve the behavior of the async-aware implementations * Basically redo all the tests * Cleanup of SQLKitBenchmark * Deprecate `SQLTriggerWhen/Event/Each/Order/Timing` in favor of better-namespaced names, add missing support for `SQLTriggerSyntax.Create.supportsDefiner` * Add SQLBetween and SQLQualifiedTable * Structural updates * Add missing predicate builder method to match the secondary predicate builder API * Misc general cleanup * Add basic support for "INSERT ... SELECT" queries to SQLInsert, add SQLSubquery and SQLSubqueryBuilder, use them in SQLCreateTableBuilder and SQLInsertBuilder * Make SQLLiteral.string and SQLIdentifier aware of proper escaping of their respective quoting. * Add all/first(decodingColumn:) utilities to SQLQueryFetcher * Add column list builders * Be more consistent about use of `String` versus `StringProtocol` and `any SQLExpression` versus `some SQLExpression`. * Add missing model decoding methods to SQLQueryFetcher. Further revise SQLRowDecoder and SQLQueryEncoder to provide the documented functionality correctly. Improve docs a bunch more. Add several missing "model"-handling methods to SQLInsertBuilder, SQLColumnUpdateBuilder, etc. Separate out the string handling utilities into their own file and refine the coding error handling. * Add SQLDataType.timestamp * Make the SQLStatement API more useful, speed up serialization very slightly, improve various other serialize(to:) methods * Make SQLDropBehavior respect the dialect, add predicate support to SQLCreateIndex, use SQLDropBehavior in SQLDropEnum (and make it respect the dialect for IF EXISTS), correct the docs and implementation of SQLDistinct, docs and serialization improvements for the rest of the query expressions. SQLDropTrigger gets a dropBehavior property, and SQLDropEnum's name is now mutable as with other properties. * Remove useless property on SQLAliasedColumnListBuilder, fix SQLColumnUpdateBuilder to correctly use SQLColumnAssignment * Make SQLPredicateBuilder and SQLSecondaryPredicateBuilder as fully consistent as possible. * Make the async version of SQLDatabase/execute a protocol requirement so non-default implementations are invoked when used through existentials * Fix SQLSelect and SQLList serialization, fix tests
- Loading branch information
Showing
150 changed files
with
11,347 additions
and
4,796 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
codecov: | ||
notify: | ||
after_n_builds: 1 | ||
wait_for_ci: false | ||
require_ci_to_pass: false | ||
comment: | ||
behavior: default | ||
layout: diff, files | ||
require_changes: true | ||
coverage: | ||
status: | ||
patch: | ||
default: | ||
branches: | ||
- ^main$ | ||
informational: true | ||
only_pulls: false | ||
paths: | ||
- ^Sources.* | ||
target: auto | ||
project: | ||
default: | ||
branches: | ||
- ^main$ | ||
informational: true | ||
only_pulls: false | ||
paths: | ||
- ^Sources.* | ||
target: auto | ||
github_checks: | ||
annotations: true | ||
ignore: | ||
- ^Sources/SQLKitBenchmark/.* | ||
- ^Tests/.* | ||
- ^.build/.* | ||
slack_app: false | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
groups: | ||
dependencies: | ||
patterns: | ||
- "*" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
64 changes: 50 additions & 14 deletions
64
Sources/SQLKit/Builders/Implementations/SQLConflictUpdateBuilder.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,78 @@ | ||
/// A builder for specifying column updates and an optional predicate to be applied to | ||
/// rows that caused unique key conflicts during an `INSERT`. | ||
public final class SQLConflictUpdateBuilder: SQLColumnUpdateBuilder, SQLPredicateBuilder { | ||
/// See ``SQLColumnUpdateBuilder/values``. | ||
public var values: [any SQLExpression] | ||
// See `SQLColumnUpdateBuilder.values`. | ||
public var values: [any SQLExpression] = [] | ||
|
||
/// See ``SQLPredicateBuilder/predicate``. | ||
public var predicate: (any SQLExpression)? | ||
// See `SQLPredicateBuilder.predicate`. | ||
public var predicate: (any SQLExpression)? = nil | ||
|
||
/// Create a conflict update builder. | ||
@usableFromInline | ||
init() { | ||
self.values = [] | ||
self.predicate = nil | ||
} | ||
init() {} | ||
|
||
/// Add an assignment of the column with the given name, using the value the column was | ||
/// given in the `INSERT` query's `VALUES` list. See ``SQLExcludedColumn``. | ||
/// given in the `INSERT` query's `VALUES` list. | ||
/// | ||
/// See ``SQLExcludedColumn`` for additional details. | ||
@inlinable | ||
@discardableResult | ||
public func set(excludedValueOf columnName: String) -> Self { | ||
self.set(excludedValueOf: SQLColumn(columnName)) | ||
} | ||
|
||
/// Add an assignment of the given column, using the value the column was given in the | ||
/// `INSERT` query's `VALUES` list. See ``SQLExcludedColumn``. | ||
/// `INSERT` query's `VALUES` list. | ||
/// | ||
/// See ``SQLExcludedColumn`` for additional details. | ||
@inlinable | ||
@discardableResult | ||
public func set(excludedValueOf column: any SQLExpression) -> Self { | ||
self.values.append(SQLColumnAssignment(settingExcludedValueFor: column)) | ||
return self | ||
} | ||
|
||
/// Encodes the given ``Encodable`` value to a sequence of key-value pairs and adds an assignment | ||
/// Encodes the given `Encodable` value to a sequence of key-value pairs and adds an assignment | ||
/// for each pair which uses the values each column was given in the original `INSERT` query's | ||
/// `VALUES` list. | ||
/// | ||
/// See ``SQLExcludedColumn`` and ``SQLQueryEncoder`` for additional details. | ||
/// | ||
/// > Important: The actual values stored in the provided `model` _are not used_ by this method. | ||
/// > The model is encoded, then the resulting values are discarded and the list of column names | ||
/// > is used to repeatedly invoke ``set(excludedValueOf:)-zmis``. This is potentially very | ||
/// > inefficient; a future version of the API will offer the ability to efficiently set the | ||
/// > excluded values for all input columns in one operation. | ||
@inlinable | ||
@discardableResult | ||
public func set( | ||
excludedContentOf model: some Encodable & Sendable, | ||
prefix: String? = nil, | ||
keyEncodingStrategy: SQLQueryEncoder.KeyEncodingStrategy = .useDefaultKeys, | ||
nilEncodingStrategy: SQLQueryEncoder.NilEncodingStrategy = .default, | ||
userInfo: [CodingUserInfoKey: any Sendable] = [:] | ||
) throws -> Self { | ||
try self.set( | ||
excludedContentOf: model, | ||
with: .init(prefix: prefix, keyEncodingStrategy: keyEncodingStrategy, nilEncodingStrategy: nilEncodingStrategy, userInfo: userInfo) | ||
) | ||
} | ||
|
||
/// Encodes the given `Encodable` value to a sequence of key-value pairs and adds an assignment | ||
/// for each pair which uses the values each column was given in the original `INSERT` query's | ||
/// `VALUES` list. See ``SQLExcludedColumn``. | ||
/// `VALUES` list. See ``SQLExcludedColumn`` and ``SQLQueryEncoder``. | ||
/// | ||
/// > Important: The actual values stored in the provided `model` _are not used_ by this method. | ||
/// > The model is encoded, then the resulting values are discarded and the list of column names | ||
/// > is used to repeatedly invoke ``set(excludedValueOf:)-zmis``. This is potentially very | ||
/// > inefficient; a future version of the API will offer the ability to efficiently set the | ||
/// > excluded values for all input columns in one operation. | ||
@inlinable | ||
@discardableResult | ||
public func set<E>(excludedContentOf model: E) throws -> Self where E: Encodable { | ||
try SQLQueryEncoder().encode(model).reduce(self) { $0.set(excludedValueOf: $1.0) } | ||
public func set( | ||
excludedContentOf model: some Encodable & Sendable, | ||
with encoder: SQLQueryEncoder | ||
) throws -> Self { | ||
try encoder.encode(model).reduce(self) { $0.set(excludedValueOf: $1.0) } | ||
} | ||
} |
Oops, something went wrong.