-
Notifications
You must be signed in to change notification settings - Fork 213
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
Support for defining WITH clauses for Common Table Expressions (CTE) #39
Conversation
- conditional support in the default adapter - tests at dataset level and also examples
Note that the beta MySQL 8.0 supports CTE; as does MariaDB 10.x
Add and improve examples, docs
8a84a4e
to
cfc8e7c
Compare
Codecov Report
@@ Coverage Diff @@
## master #39 +/- ##
=========================================
- Coverage 83.66% 83.06% -0.6%
=========================================
Files 17 17
Lines 2020 2085 +65
=========================================
+ Hits 1690 1732 +42
- Misses 233 246 +13
- Partials 97 107 +10
Continue to review full report at Codecov.
|
Found an issue with the Travis build; see my last commit for the fix for the "vanity" package name (from the Travis docs). Wondering what you recommend on the coverage test results -- are there any particular tests you'd recommend that I'm missing? |
@Oscil8 Ill take a look at this either later today or tomorrow thanks for the pr! |
Any comments @doug-martin ? |
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.
Thanks for adding this it looks great! Please fix the one formatting issue and Ill merge this!
default_adapter.go
Outdated
@@ -217,6 +225,8 @@ func NewDefaultAdapter(ds *Dataset) Adapter { | |||
SelectClause: default_select_clause, | |||
DeleteClause: default_delete_clause, | |||
TruncateClause: default_truncate_clause, | |||
WithFragment: default_with_fragment, | |||
RecursiveFragment: default_recursive_fragment, |
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.
Formatting
Addressed the formatting issue |
Thanks for this great library; I've found it very useful and filled my needs for query generation. Just found one missing element that did exist in some of the other major query generators which is support for Common Table Expressions (CTEs), i.e. WITH clauses. This includes both WITH and WITH RECURSIVE versions and applies them to SELECT, UPDATE, DELETE and INSERT queries (although I am just using them in the SELECT context).
These are a useful way to build efficient queries by re-using commonly used subparts. They are supported in PostgreSQL (https://www.postgresql.org/docs/current/static/queries-with.html) and SQLite (https://sqlite.org/lang_with.html); and I noticed in the upcoming MySQL 8.0 currently in Beta (https://dev.mysql.com/doc/refman/8.0/en/with.html). I'm using PostgreSQL.
Would appreciate your feedback on the way I have added the WITH clauses to goqu; as well as appropriate level of test and documentation. I aimed for a similar level as for the Union and related clauses.