-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add CQL support #85
Add CQL support #85
Conversation
SpencerC
commented
Sep 8, 2022
•
edited
Loading
edited
- Add CQL flavor.
- Add support for CQL argument compilation.
- Adopt substests for interpolation tests.
- Add support for CQL interpolation.
- Add support for CQL blobs: https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/blob_r.html
- Add CQL timestamp interpolation support: https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/timestamp_type_r.html
- Add builder test for CQL.
- Add support for the NOW function: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/timeuuid_functions_r.html?hl=now
- Add support for CQL update IF statement: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlUpdate.html#Conditionallyupdatingcolumns
- Drop table prefixes for CQL SELECTs.
- Switch to single quoting for CQL queries: https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/escape_char_r.html
- Update documentation.
- Use valid CQL in tests.
- Support CQL LIMIT.
* Add CQL flavor. * Add support for CQL argument compilation. * Adopt substests for interpolation tests. * Add support for CQL interpolation. * Add support for CQL blobs. https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/blob_r.html * Add CQL timestamp interpolation support. https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/timestamp_type_r.html * Add builder test for CQL. * Add support for the NOW function. https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/timeuuid_functions_r.html?hl=now * Add support for CQL update IF statement. https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/cqlUpdate.html#Conditionallyupdatingcolumns * Drop table prefixes for CQL SELECTs. * Switch to single quoting for CQL queries. https://docs.datastax.com/en/cql-oss/3.3/cql/cql_reference/escape_char_r.html * Update documentation. * Use valid CQL in tests. * Support CQL LIMIT.
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 a lot for your contribution. I leave some review comments here. We can discuss in this PR thread.
modifiers.go
Outdated
@@ -72,6 +72,11 @@ func Raw(expr string) interface{} { | |||
return rawArgs{expr} | |||
} | |||
|
|||
// Now returns a raw value comprising the NOW() function. | |||
func Now() interface{} { |
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.
It's not recommended to add this method. There are tons of functions in every DBMS. NOW()
is not the one which is extremely outstanding and must be added in this package.
BTW, SQLServer doesn't have NOW()
. The equivalent one is SYSDATETIME()
.
update.go
Outdated
@@ -157,6 +159,13 @@ func (ub *UpdateBuilder) Limit(limit int) *UpdateBuilder { | |||
return ub | |||
} | |||
|
|||
// If sets IF expressions for UPDATE. | |||
func (ub *UpdateBuilder) If(andExpr ...string) *UpdateBuilder { |
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.
It's not recommended to add this method. IF
is a CQL-specific extension. AFAIK, there is no other DBMS supporting this. I recommend you to implement this in your CQL business code.
func CQLUpdateIf(ub *sqlbuilder.UpdateBuilder, andExpr ...string) *sqlbuilder.UpdateBuilder {
ub.SQL("IF")
ub.SQL(strings.Join(andExprs, " AND "))
return ub
}
As you can see, this package mainly defines methods for keywords available in ISO SQL-2016 spec, which is a subset of all DBMS implementations, with a few exceptions. I do think it's not convenient for users who build SQL with only one flavor. There is a long standing issue #60 (in Chinese) in which the support to ON DUPLICATE KEY UPDATE
is requested. I cannot resolve this issue as SQL syntax for duplicate key differs a lot in different DBMS. It's hard to define a unified method for this feature.
A possible way to support flavor-specific keywords is to create sub-package for every flavor, e.g. github.com/huandu/go-sqlbuilder/cql
for CQL, and then define methods based on the flavor's SQL spec. However, there will be a lot of work to do so.
@SpencerC Could you update your PR per my review comments? Feel free to comment on my comments. |
Yep, have some other work to finish first. |
Got it. |
* ignore unexported fields that are not embedded structs * fix huandu#74 [BREAKING CHANGE] Select#GroupBy and Select#OrderBy behavior change. Previous, GroupBy and OrderBy only keep the columns in the last call. Now, all columns are kept. * fix huandu#75 add Struct#Columns/ColumnsForTag and Struct#Values/ValuesForTag * remove a call to StructField.IsExported as it is not in go1.13 * refs huandu#78 add new `fieldas` tag to set AS name for SELECT * update docs * fix huandu#81 refactory struct field parser to make fieldas correct in all cases * Add Gitter badge * Fix insert ignore for postgres and sqlite. * fix test Co-authored-by: Michał Dobaczewski <mdobak@gmail.com> Co-authored-by: Huan Du <i@huandu.me> Co-authored-by: The Gitter Badger <badger@gitter.im> Co-authored-by: Zhong Ren <zhong@zhongren.me>
# Conflicts: # README.md # args.go # flavor.go # insert_test.go # interpolate.go # interpolate_test.go # select_test.go # struct.go # struct_test.go
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.
There are some compile errors in test case. Please fix them. Thanks.
Apologies, should be fixed now. |
LGTM. Thanks a lot for your time, @SpencerC ! |
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.
LGTM.