Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
dev: skeleton to support clickhouse
  • Loading branch information
CNLHC committed Mar 26, 2024
commit 58ac45801b723036f9ffe8809c9d797bb4f36d36
3 changes: 3 additions & 0 deletions internal/cmd/vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
// SQLite really doesn't want us to depend on the output of EXPLAIN
// QUERY PLAN: https://www.sqlite.org/eqp.html
expl = nil
case config.EngineClickhouse:
// TODO(clickhouse): ch-toko
panic("not implemented(ch-todo)")
default:
return fmt.Errorf("unsupported database uri: %s", s.Engine)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/sqlc-dev/sqlc/internal/analyzer"
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
"github.com/sqlc-dev/sqlc/internal/engine/dolphin"
"github.com/sqlc-dev/sqlc/internal/engine/postgresql"
pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer"
Expand Down Expand Up @@ -40,6 +41,9 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err
}

switch conf.Engine {
case config.EngineClickhouse:
c.parser = clickhouse.NewParser()
c.catalog = clickhouse.NewCatalog()
case config.EngineSQLite:
c.parser = sqlite.NewParser()
c.catalog = sqlite.NewCatalog()
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
EngineMySQL Engine = "mysql"
EnginePostgreSQL Engine = "postgresql"
EngineSQLite Engine = "sqlite"
EngineClickhouse Engine = "clickhouse"
)

type Config struct {
Expand Down
18 changes: 18 additions & 0 deletions internal/engine/clickhouse/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package clickhouse

import "github.com/sqlc-dev/sqlc/internal/sql/catalog"

func NewCatalog() *catalog.Catalog {
def := "main"
return &catalog.Catalog{
DefaultSchema: def,
Schemas: []*catalog.Schema{
// defaultSchema(def),
},
Extensions: map[string]struct{}{},
}
}

func newTestCatalog() *catalog.Catalog {
return catalog.New("main")
}
27 changes: 27 additions & 0 deletions internal/engine/clickhouse/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package clickhouse

import (
"io"

"github.com/sqlc-dev/sqlc/internal/source"
"github.com/sqlc-dev/sqlc/internal/sql/ast"
)

type Parser struct {
}

func NewParser() *Parser {
return &Parser{}
}

func (c *Parser) Parse(io.Reader) ([]ast.Statement, error) {

return []ast.Statement{}, nil
}
func (c *Parser) CommentSyntax() source.CommentSyntax {
return source.CommentSyntax{}

}
func (c *Parser) IsReservedKeyword(string) bool {
return false
}