Skip to content

Commit 323187f

Browse files
authored
feat(sqlite): Start expanding support (#1410)
Support the following features: * CREATE TABLE LIKE * ALTER TABLE DROP COLUMN * SELECT count(*) ...
1 parent dd3b2b8 commit 323187f

File tree

29 files changed

+2768
-2383
lines changed

29 files changed

+2768
-2383
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kyleconroy/sqlc
33
go 1.17
44

55
require (
6-
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976
6+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9
77
github.com/davecgh/go-spew v1.1.1
88
github.com/go-sql-driver/mysql v1.6.0
99
github.com/google/go-cmp v0.5.7

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
5959
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
6060
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976 h1:vvvbSbmHS27Ayx0fAeFAR4chZoobj9RTYMlTIouSKgY=
6161
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
62+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 h1:zvkJv+9Pxm1nnEMcKnShREt4qtduHKz4iw4AB4ul0Ao=
63+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
6264
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
6365
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
6466
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=

internal/compiler/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) *Compiler {
2424
switch conf.Engine {
2525
case config.EngineXLemon:
2626
c.parser = sqlite.NewParser()
27-
c.catalog = catalog.New("main")
27+
c.catalog = sqlite.NewCatalog()
2828
case config.EngineMySQL:
2929
c.parser = dolphin.NewParser()
3030
c.catalog = dolphin.NewCatalog()

internal/endtoend/testdata/count_star/sqlite/go/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/count_star/sqlite/go/models.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/count_star/sqlite/go/query.sql.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- name: CountStarLower :one
2+
SELECT count(*) FROM bar;
3+
4+
-- name: CountStarUpper :one
5+
SELECT COUNT(*) FROM bar;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE bar (id BIGINT not null);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"name": "querytest",
7+
"engine": "_lemon",
8+
"schema": "schema.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

internal/endtoend/testdata/ddl_alter_table_drop_column/sqlite/go/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_alter_table_drop_column/sqlite/go/models.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_alter_table_drop_column/sqlite/go/query.sql.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: Placeholder :exec
2+
SELECT 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE TABLE foo (bar text, baz text);
2+
ALTER TABLE foo DROP COLUMN bar;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"engine": "_lemon",
7+
"name": "querytest",
8+
"schema": "schema.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

internal/endtoend/testdata/ddl_create_table/sqlite/go/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_create_table/sqlite/go/models.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/ddl_create_table/sqlite/go/query.sql.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: Placeholder :exec
2+
SELECT 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE venues (name text);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"engine": "_lemon",
7+
"name": "querytest",
8+
"schema": "schema.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

internal/engine/sqlite/catalog.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ package sqlite
33
import "github.com/kyleconroy/sqlc/internal/sql/catalog"
44

55
func NewCatalog() *catalog.Catalog {
6-
c := catalog.New("main")
7-
return c
6+
def := "main"
7+
return &catalog.Catalog{
8+
DefaultSchema: def,
9+
Schemas: []*catalog.Schema{
10+
defaultSchema(def),
11+
},
12+
Extensions: map[string]struct{}{},
13+
}
14+
}
15+
16+
func newTestCatalog() *catalog.Catalog {
17+
return catalog.New("main")
818
}

internal/engine/sqlite/catalog_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ func TestUpdate(t *testing.T) {
239239
t.Fatal(err)
240240
}
241241

242-
c := NewCatalog()
242+
c := newTestCatalog()
243243
if err := c.Build(stmts); err != nil {
244244
t.Log(test.stmt)
245245
t.Fatal(err)
246246
}
247247

248-
e := NewCatalog()
248+
e := newTestCatalog()
249249
if test.s != nil {
250250
var replaced bool
251251
for i := range e.Schemas {

0 commit comments

Comments
 (0)