Skip to content

Commit c215af2

Browse files
kyleconroyclaude
andcommitted
feat: add ClickHouse database engine support
Add ClickHouse support using the github.com/sqlc-dev/doubleclick parser library. New files in internal/engine/clickhouse/: - parse.go: Parser implementation using doubleclick - convert.go: AST converter from doubleclick to sqlc AST - format.go: ClickHouse-specific SQL formatting - catalog.go: Catalog initialization - stdlib.go: Standard library functions - reserved.go: Reserved keywords - utils.go: Helper functions - parse_test.go: Unit tests Supported SQL operations: - SELECT with JOINs, subqueries, CTEs, window functions - INSERT with VALUES and SELECT subquery - UPDATE and DELETE - CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2e0435c commit c215af2

File tree

12 files changed

+1616
-6
lines changed

12 files changed

+1616
-6
lines changed

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/sqlc-dev/sqlc
22

3-
go 1.24.0
4-
5-
toolchain go1.24.1
3+
go 1.24.7
64

75
require (
86
github.com/antlr4-go/antlr/v4 v4.13.1
@@ -48,6 +46,7 @@ require (
4846
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
4947
github.com/pingcap/log v1.1.0 // indirect
5048
github.com/rogpeppe/go-internal v1.10.0 // indirect
49+
github.com/sqlc-dev/doubleclick v1.0.0 // indirect
5150
github.com/stoewer/go-strcase v1.2.0 // indirect
5251
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
5352
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiT
157157
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
158158
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
159159
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
160+
github.com/sqlc-dev/doubleclick v1.0.0 h1:2/OApfQ2eLgcfa/Fqs8WSMA6atH0G8j9hHbQIgMfAXI=
161+
github.com/sqlc-dev/doubleclick v1.0.0/go.mod h1:ODHRroSrk/rr5neRHlWMSRijqOak8YmNaO3VAZCNl5Y=
160162
github.com/sqlc-dev/mysql v0.0.0-20251129233104-d81e1cac6db2 h1:kmCAKKtOgK6EXXQX9oPdEASIhgor7TCpWxD8NtcqVcU=
161163
github.com/sqlc-dev/mysql v0.0.0-20251129233104-d81e1cac6db2/go.mod h1:TrDMWzjNTKvJeK2GC8uspG+PWyPLiY9QKvwdWpAdlZE=
162164
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=

internal/compiler/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/sqlc-dev/sqlc/internal/analyzer"
88
"github.com/sqlc-dev/sqlc/internal/config"
99
"github.com/sqlc-dev/sqlc/internal/dbmanager"
10+
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
1011
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
1112
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1213
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
@@ -82,6 +83,10 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings, parserOpts opts
8283
c.parser = dolphin.NewParser()
8384
c.catalog = dolphin.NewCatalog()
8485
c.selector = newDefaultSelector()
86+
case config.EngineClickHouse:
87+
c.parser = clickhouse.NewParser()
88+
c.catalog = clickhouse.NewCatalog()
89+
c.selector = newDefaultSelector()
8590
case config.EnginePostgreSQL:
8691
parser := postgresql.NewParser()
8792
c.parser = parser

internal/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error {
5151
}
5252

5353
const (
54-
EngineMySQL Engine = "mysql"
55-
EnginePostgreSQL Engine = "postgresql"
56-
EngineSQLite Engine = "sqlite"
54+
EngineMySQL Engine = "mysql"
55+
EnginePostgreSQL Engine = "postgresql"
56+
EngineSQLite Engine = "sqlite"
57+
EngineClickHouse Engine = "clickhouse"
5758
)
5859

5960
type Config struct {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package clickhouse
2+
3+
import (
4+
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
5+
)
6+
7+
func NewCatalog() *catalog.Catalog {
8+
def := "default" // ClickHouse default database
9+
return &catalog.Catalog{
10+
DefaultSchema: def,
11+
Schemas: []*catalog.Schema{
12+
defaultSchema(def),
13+
},
14+
Extensions: map[string]struct{}{},
15+
}
16+
}

0 commit comments

Comments
 (0)