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

Add CQL support #85

Merged
merged 6 commits into from
Jan 11, 2023
Merged

Add CQL support #85

merged 6 commits into from
Jan 11, 2023

Conversation

SpencerC
Copy link
Contributor

@SpencerC SpencerC commented Sep 8, 2022

* 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.
Copy link
Owner

@huandu huandu left a 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{} {
Copy link
Owner

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 {
Copy link
Owner

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.

@huandu
Copy link
Owner

huandu commented Sep 21, 2022

@SpencerC Could you update your PR per my review comments? Feel free to comment on my comments.

@SpencerC
Copy link
Contributor Author

Yep, have some other work to finish first.

@huandu
Copy link
Owner

huandu commented Sep 22, 2022

Got it.

SpencerC added a commit to datastax-ext/go-sqlbuilder that referenced this pull request Sep 25, 2022
SpencerC and others added 2 commits November 30, 2022 10:57
* 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
@SpencerC SpencerC requested a review from huandu January 5, 2023 15:24
Copy link
Owner

@huandu huandu left a 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.

@SpencerC
Copy link
Contributor Author

SpencerC commented Jan 9, 2023

Apologies, should be fixed now.

@SpencerC SpencerC requested a review from huandu January 9, 2023 21:34
@coveralls
Copy link

Coverage Status

Coverage: 96.191% (+0.04%) from 96.154% when pulling 28a0bcf on datastax-ext:master into f5453c8 on huandu:master.

@huandu
Copy link
Owner

huandu commented Jan 11, 2023

LGTM. Thanks a lot for your time, @SpencerC !

@huandu huandu merged commit 674f3da into huandu:master Jan 11, 2023
Copy link
Owner

@huandu huandu left a comment

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants