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 clickhouse support #264

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

pablomatiasgomez
Copy link
Contributor

@pablomatiasgomez pablomatiasgomez commented Jun 19, 2024

  • Add support for clickhouse dialect. No breaking changes for all the other dialects, but had to change many things to support it.
  • Added integration tests including the docker image.

cc @cypriss / @taylorchu

dbr_test.go Outdated
@@ -100,73 +131,78 @@ func reset(t *testing.T, sess *Session) {

func TestBasicCRUD(t *testing.T) {
for _, sess := range testSession {
reset(t, sess)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no big change here, I just changed the test name to include the dialect, otherwise it's difficult to see which one was failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed all tests to be this way in https://github.com/gocraft/dbr/pull/268/files

@pablomatiasgomez pablomatiasgomez marked this pull request as ready for review June 19, 2024 21:08
@@ -2,11 +2,12 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.17
- image: cimg/go:1.21
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per https://hub.docker.com/r/cimg/go circleci/golang was deprecated in favor of cimg/go

@pablomatiasgomez
Copy link
Contributor Author

@cypriss @taylorchu if you feel the PR ended up being too big, I'm happy to split it in a few, to make it easier to review, let me know

Copy link

@santileira santileira left a comment

Choose a reason for hiding this comment

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

Some improvements to be more go idiomatic.

Also, I would use clickHouse / ClickHouse instead of clickhouse / Clickhouse

README.md Outdated Show resolved Hide resolved
README.md.tpl Outdated Show resolved Hide resolved
branch.go Outdated Show resolved Hide resolved
branch.go Outdated Show resolved Hide resolved
branch.go Outdated Show resolved Hide resolved
mysql
}

func (d clickhouse) EncodeTime(t time.Time) string {

Choose a reason for hiding this comment

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

should the receiver be c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the dialects have a received named d. I wanted to preserve the same naming

interpolate.go Outdated Show resolved Hide resolved
join.go Outdated
@@ -4,15 +4,21 @@ type joinType uint8

const (
inner joinType = iota
allFull

Choose a reason for hiding this comment

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

is this going to affect something? because the iota for left, right and full will change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are only used internally and are kind of enums to know which string to write, so shouldn't affect

settings.go Outdated Show resolved Hide resolved
update.go Outdated Show resolved Hide resolved
@@ -13,4 +13,11 @@ type Dialect interface {
EncodeBytes(b []byte) string

Placeholder(n int) string

UpdateStmts() (string, string)
Copy link
Contributor

Choose a reason for hiding this comment

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

could you comment on why each is added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • UpdateStmts was added to know what is the staement that has to be used to run UPDATEs. Unfortunatelly clickhosue is different in this part, it's in the shape of ALTER TABLE ... UPDATE key = value compared to others where it's UPDATE ... SET key = value
  • OnConflict adds support to add actions for constraint violation, e.g UPSERT. This works in postgres, mysql, etc. I can maybe add this change in a separate PR if you think it would be better to review, let me know if you want me to split this into smaller PRs, happy to do.
  • Proposed is used with OnConflict as reference to proposed value in on conflict clause. You can see the TestOnConflict to see how it works.
  • SupportsOn was added for clickhouse explicitly, but I removed it for now, I can maybe add it later if we really need to use it, and I think it should be done in a different way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created a separate PR for the CI updates #265 I can then split this into more pieces if that's ok.

@pablomatiasgomez pablomatiasgomez marked this pull request as draft July 3, 2024 03:08
@pablomatiasgomez
Copy link
Contributor Author

@taylorchu I removed things that were not specific to clickhouse from this PR and created:

which are ready to be reviewed. Let me know your thoughts! 🙌

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

Successfully merging this pull request may close these issues.

3 participants