-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add support for the WITH clause #1139
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12e2166
Add support for the WITH clause
marmphco 03b5688
documentation
marmphco 76d34dd
Heed linter warnings
marmphco bdacf4d
Slight documentation tweak
marmphco ced1851
Move WITH support members to extension in Query+with.swift
marmphco ed43285
Move WithClauses to Query+with.swift
marmphco 0dfc7b0
MaterializationHint > Query+with
marmphco cfa6010
Split test cases
marmphco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Heed linter warnings
Note sure how to get the line length of Query back down below 500 without harming readability though.
- Loading branch information
commit 76d34dd8ff668b58d6b5530528460dd6d2786c0e
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,7 @@ class QueryTests: XCTestCase { | |
| func test_selectDistinct_withStar_compilesSelectClause() { | ||
| assertSQL("SELECT DISTINCT * FROM \"users\"", users.select(distinct: *)) | ||
| } | ||
|
|
||
| func test_union_compilesUnionClause() { | ||
| assertSQL("SELECT * FROM \"users\" UNION SELECT * FROM \"posts\"", users.union(posts)) | ||
| assertSQL("SELECT * FROM \"users\" UNION ALL SELECT * FROM \"posts\"", users.union(all: true, posts)) | ||
|
|
@@ -224,41 +224,41 @@ class QueryTests: XCTestCase { | |
| users.join(managers, on: managers[id] == users[managerId]) | ||
| ) | ||
| } | ||
|
|
||
| func test_with_compilesWithClause() { | ||
| let temp = Table("temp") | ||
|
|
||
| assertSQL("WITH \"temp\" AS (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, as: users)) | ||
| } | ||
|
|
||
| func test_with_recursive_compilesWithClause() { | ||
|
||
| let temp = Table("temp") | ||
|
|
||
| assertSQL("WITH RECURSIVE \"temp\" AS (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, recursive: true, as: users)) | ||
|
|
||
| assertSQL("WITH \"temp\" AS (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, recursive: false, as: users)) | ||
| } | ||
|
|
||
| func test_with_materialization_compilesWithClause() { | ||
|
||
| let temp = Table("temp") | ||
|
|
||
| assertSQL("WITH \"temp\" AS MATERIALIZED (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, materializationHint: .materialized, as: users)) | ||
| temp.with(temp, hint: .materialized, as: users)) | ||
|
|
||
| assertSQL("WITH \"temp\" AS NOT MATERIALIZED (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, materializationHint: .notMaterialized, as: users)) | ||
| temp.with(temp, hint: .notMaterialized, as: users)) | ||
| } | ||
|
|
||
| func test_with_columns_compilesWithClause() { | ||
| let temp = Table("temp") | ||
|
|
||
| assertSQL("WITH \"temp\" (\"id\", \"email\") AS (SELECT * FROM \"users\") SELECT * FROM \"temp\"", | ||
| temp.with(temp, columns: [id, email], recursive: false, materializationHint: nil, as: users)) | ||
| temp.with(temp, columns: [id, email], recursive: false, hint: nil, as: users)) | ||
| } | ||
|
|
||
| func test_with_multiple_compilesWithClause() { | ||
| let temp = Table("temp") | ||
| let second = Table("second") | ||
|
|
@@ -267,8 +267,8 @@ class QueryTests: XCTestCase { | |
| let query = temp | ||
| .with(temp, recursive: true, as: users) | ||
| .with(second, recursive: true, as: posts) | ||
| .with(third, materializationHint: .materialized, as:categories) | ||
| .with(third, hint: .materialized, as: categories) | ||
|
|
||
| assertSQL( | ||
| """ | ||
| WITH RECURSIVE \"temp\" AS (SELECT * FROM \"users\"), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split:
test_union_compiles_Union_Clausetest_union_compiles_Union_All_ClauseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split the tests in cfa6010. I kept the names in the form
test_union_compilesUnionAllClausefor consistency with the existing tests. Let me know if I should instead dotest_union_compiles_Union_All_Clause.