Skip to content

Commit 4f43670

Browse files
committed
core: address review — move shim/DDL apply out of engine and compiler
Move pluginCatalogFromCore into a new internal/core/shim package as PluginCatalog. Move the engine-neutral DDL apply into a new internal/core/schema package and have the compiler call it directly, so no clickhouse-specific code remains in the schema loading loop. Push the ClickHouse type unwrapping into the engine's column conversion so the core schema apply only sees canonical scalar types. Rename the core compile path file to parse_core.go. Remove the unit tests in favor of end-to-end coverage.
1 parent 59e579d commit 4f43670

12 files changed

Lines changed: 119 additions & 528 deletions

File tree

internal/cmd/shim.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/sqlc-dev/sqlc/internal/compiler"
55
"github.com/sqlc-dev/sqlc/internal/config"
66
"github.com/sqlc-dev/sqlc/internal/config/convert"
7-
"github.com/sqlc-dev/sqlc/internal/core"
7+
coreshim "github.com/sqlc-dev/sqlc/internal/core/shim"
88
"github.com/sqlc-dev/sqlc/internal/info"
99
"github.com/sqlc-dev/sqlc/internal/plugin"
1010
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
@@ -227,7 +227,7 @@ func pluginQueryParam(p compiler.Parameter) *plugin.Parameter {
227227
func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugin.GenerateRequest {
228228
var cat *plugin.Catalog
229229
if r.CoreCatalog != nil {
230-
cat = pluginCatalogFromCore(r.CoreCatalog)
230+
cat = coreshim.PluginCatalog(r.CoreCatalog)
231231
} else {
232232
cat = pluginCatalog(r.Catalog)
233233
}
@@ -238,42 +238,3 @@ func codeGenRequest(r *compiler.Result, settings config.CombinedSettings) *plugi
238238
SqlcVersion: info.Version,
239239
}
240240
}
241-
242-
func pluginCatalogFromCore(cc *core.Catalog) *plugin.Catalog {
243-
var schemas []*plugin.Schema
244-
245-
namespaces, err := cc.Namespaces()
246-
if err != nil {
247-
return &plugin.Catalog{DefaultSchema: "public"}
248-
}
249-
for _, ns := range namespaces {
250-
tables, err := cc.TablesInNamespace(ns.OID)
251-
if err != nil {
252-
continue
253-
}
254-
var ptables []*plugin.Table
255-
for _, cl := range tables {
256-
rel := &plugin.Identifier{Schema: ns.Name, Name: cl.Name}
257-
cols, err := cc.ClassCodegenColumns(cl.OID)
258-
if err != nil {
259-
continue
260-
}
261-
var columns []*plugin.Column
262-
for _, col := range cols {
263-
columns = append(columns, &plugin.Column{
264-
Name: col.Name,
265-
Type: &plugin.Identifier{Name: col.TypeName},
266-
NotNull: col.NotNull,
267-
Table: rel,
268-
})
269-
}
270-
ptables = append(ptables, &plugin.Table{Rel: rel, Columns: columns})
271-
}
272-
schemas = append(schemas, &plugin.Schema{Name: ns.Name, Tables: ptables})
273-
}
274-
275-
return &plugin.Catalog{
276-
DefaultSchema: "public",
277-
Schemas: schemas,
278-
}
279-
}

internal/compiler/compile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/sqlc-dev/sqlc/internal/engine/clickhouse"
12+
coreschema "github.com/sqlc-dev/sqlc/internal/core/schema"
1313
"github.com/sqlc-dev/sqlc/internal/migrations"
1414
"github.com/sqlc-dev/sqlc/internal/multierr"
1515
"github.com/sqlc-dev/sqlc/internal/opts"
@@ -58,7 +58,7 @@ func (c *Compiler) parseCatalog(schemas []string) error {
5858

5959
if c.coreCatalog != nil {
6060
for i := range stmts {
61-
if err := clickhouse.Apply(c.coreCatalog, stmts[i].Raw); err != nil {
61+
if err := coreschema.Apply(c.coreCatalog, stmts[i].Raw); err != nil {
6262
merr.Add(filename, contents, stmts[i].Pos(), err)
6363
continue
6464
}

internal/core/analyzer/analyzer_test.go

Lines changed: 0 additions & 100 deletions
This file was deleted.

internal/core/cast_test.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

internal/core/dialect_test.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

internal/core/operator_test.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

internal/core/proc_test.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)