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

Major overhaul of the entire SQLKit package #172

Merged
merged 87 commits into from
Apr 13, 2024
Merged

Major overhaul of the entire SQLKit package #172

merged 87 commits into from
Apr 13, 2024

Conversation

gwynne
Copy link
Member

@gwynne gwynne commented Mar 20, 2024

This will be the last release of SQLKit version 3.

A hopefully complete (but probably not) list of significant changes:

  • A massive sweep to add at least minimal documentation to everything in the package.
  • 100% test coverage.
  • Reorganized the source code layout
  • Require Swift 5.8
  • Package is now ExistentialAny-compliant
  • Numerous poorly-designed APIs have been deprecated. Replacement suggestions are available in all cases.
  • 100% Sendable-complaint (zero concurrency warnings).
  • SQLDatabaseReportedVersion is now Equatable and Comparable, as it ought to have been from the start.
  • Efficiency improvements for the async versions of various APIs.
  • SQLQueryEncoder and SQLRowDecoder have been massively overhauled; both are now considerably more flexible and less restrictive.
  • SQLBenchmark is now async.
  • Numerous ugly assert()s and print()s are now consistently routed through the database's logger instead, and less noisy logging is done.
  • Several bits of missing functionality in SQLCreateTrigger are now correctly implemented.
  • SQLIdentifier and SQLLiteral.string now automatically escape the appropriate quote characters when serializing.
  • Added SQLBetween (x BETWEEN y AND z), SQLQualifiedTable (schema.table), SQLSubquery and SQLSubqueryBuilder, SQLUnqualifiedColumnListBuilder, and SQLAliasedColumnListBuilder.
  • SQLPredicateBuilder and SQLSecondaryPredicateBuilder now provide 1-to-1 corresponding APIs for all four variants ("and where", "and having", "or where", "or having").
  • Serialization of expressions is now a bit faster across the board.
  • SQLInsert and SQLInsertBuilder now support the INSERT ... SELECT syntax.
  • SQLQueryFetcher gained a number of convenience APIs for decoding models and single columns. Several builders also gained convenience methods for encoding or decoding of models. (Note that "models" in this usage does NOT refer to Fluent's Model protocol, but rather to any Codable structure.)
  • SQLDropBehavior is now used by all builders that support the modifier and respects the current dialect properly.
  • SQLCreateIndex now supports index predicates.
  • SQLDistinct now serializes correctly.
  • Several expressions and queries are now more tolerant of missing configuration when serialized.
  • SQLDatabase gained a withSession(_:) API which, when implemented correctly by drivers, allows implementing transactions safely using pure SQLKit (no need for Fluent-level or driver-level intervention).
  • SQLColumnConstraintAlgorithm.primaryKey no longer emits incorrect SQL if the active dialect uses NULL as its DEFAULT literal.

@gwynne gwynne added bug Something isn't working enhancement New feature or request semver-minor Contains new APIs labels Mar 20, 2024
@gwynne gwynne marked this pull request as ready for review March 24, 2024 14:34
@gwynne gwynne requested a review from 0xTim as a code owner March 24, 2024 14:34
Copy link

codecov bot commented Mar 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7d36d6c) to head (402b919).

Additional details and impacted files
@@             Coverage Diff             @@
##           main      #172        +/-   ##
===========================================
+ Coverage      0   100.00%   +100.00%     
===========================================
  Files         0        97        +97     
  Lines         0      2603      +2603     
===========================================
+ Hits          0      2603      +2603     
Files Coverage Δ
...Builders/Implementations/SQLAlterEnumBuilder.swift 100.00% <ø> (ø)
...uilders/Implementations/SQLAlterTableBuilder.swift 100.00% <ø> (ø)
...ers/Implementations/SQLConflictUpdateBuilder.swift 100.00% <100.00%> (ø)
...uilders/Implementations/SQLCreateEnumBuilder.swift 100.00% <ø> (ø)
...ilders/Implementations/SQLCreateIndexBuilder.swift 100.00% <100.00%> (ø)
...ilders/Implementations/SQLCreateTableBuilder.swift 100.00% <100.00%> (ø)
...ders/Implementations/SQLCreateTriggerBuilder.swift 100.00% <100.00%> (ø)
...it/Builders/Implementations/SQLDeleteBuilder.swift 100.00% <ø> (ø)
.../Builders/Implementations/SQLDropEnumBuilder.swift 100.00% <100.00%> (ø)
...Builders/Implementations/SQLDropIndexBuilder.swift 100.00% <100.00%> (ø)
... and 87 more

Copy link
Member

@ptoffy ptoffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits around comments, text etc.

Sources/SQLKit/Docs.docc/SQLKit.md Outdated Show resolved Hide resolved
Sources/SQLKit/Docs.docc/SQLKit.md Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/Basics/SQLDirection.swift Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/Basics/SQLDirection.swift Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/Basics/SQLQueryString.swift Outdated Show resolved Hide resolved
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this LGTM. I have a few comments about API breakages, but I'm not sure if they're true or not.

Great to see lots of extra tests and documentation coverage. I will say this PR is very hard to review due to the sheer size and changes involved, it probably would have been better to break it up into separate PRs as there's definitely places where things could be missed

@gwynne gwynne force-pushed the overhaul branch 2 times, most recently from e8766e5 to a02ebb0 Compare March 31, 2024 18:19
@gwynne gwynne force-pushed the overhaul branch 2 times, most recently from ab6d9e0 to 7c76908 Compare April 1, 2024 18:33
gwynne added 19 commits April 1, 2024 13:35
…ions, add SQLConflictResolutionStrategy API, fix SQLCreateIndex and SQLCreateTrigger serialization
…, for example, safely implementing transactions. Make SQLReportedDatabaseVersion slightly less awkward. Add test coverage.
… the primary key column constraint algorithm and add additional coverage to tests for non-default scenarios.
… codable SQLExpressions, fix un-dropped enum type when dialect uses type name enums, maintain test coverage.
…them. These are not intended for users. Rename FakeSendable->FakeSendableCodable, make it slightly more capable, include it in the SPI
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some queries, but looks good to go for the most part

Sources/SQLKit/Expressions/Clauses/SQLExcludedColumn.swift Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/Clauses/SQLReturning.swift Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/Queries/SQLAlterTable.swift Outdated Show resolved Hide resolved
Sources/SQLKit/Expressions/SQLStatement.swift Show resolved Hide resolved
Sources/SQLKit/Expressions/Syntax/SQLBinaryOperator.swift Outdated Show resolved Hide resolved
@gwynne gwynne merged commit f1263a2 into main Apr 13, 2024
13 of 14 checks passed
@gwynne gwynne deleted the overhaul branch April 13, 2024 20:00
self.sql = sql
self.binds = binds
}

@inlinable
public func serialize(to serializer: inout SQLSerializer) {
serializer.write(self.sql)
serializer.binds += self.binds
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, this removal makes this a (pretty big) breaking change. I'm not sure there's anything to be done about it now, since the release was, I believe, quite a while ago. But just a note for the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a very much deliberate breakage. This particular "functionality" of SQLRaw was a misfeature accidentally left in the code during Tanner's work on Vapor 4; it should never have been present to begin with. I couldn't remove the binds property itself without causing source breakage, but I could at least discourage its usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said...

If you are a user whose code was broken by this change, I'm not dead-set against undoing it, even this long afterwards; putting it back would be a purely additive change. The binds property will be gone anyway in Fluent 5, so it doesn't matter as much for Fluent 4 at this point.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't personally need it (I only used it in two places, and I figured out the \(bind: bindVal) thing). I just think it's unexpected for a minor version bump to remove significant (though apparently unintentional) runtime functionality with only a compile-time warning as an indication

Idk if this project uses Semver. If not, then the expectation that that wouldn't happen is my fault, and you should just ignore me :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but I made an executive decision to sidestep the rules, since the functionality was never intended to exist in the first place. You're the first to notice (or at least, the first to say something about it), if truth be told 😅.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to nitpick 😅 - SemVer definitely allows breaking behaviour changes, otherwise you'd never be able to fix bugs as that's a change in behaviour. SemVer is purely about API changes, and in Swift's case, whether something still compiles, not if it behaves the same way (not saying that's any comfort for having something major changed and we tend to try and avoid that in most places)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request semver-minor Contains new APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants