Skip to content

Commit

Permalink
feat(sqlite): Start expanding support (#1410)
Browse files Browse the repository at this point in the history
Support the following features:
* CREATE TABLE LIKE
* ALTER TABLE DROP COLUMN
* SELECT count(*) ...
  • Loading branch information
PadraigK committed Feb 12, 2022
1 parent dd3b2b8 commit 323187f
Show file tree
Hide file tree
Showing 29 changed files with 2,768 additions and 2,383 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -3,7 +3,7 @@ module github.com/kyleconroy/sqlc
go 1.17

require (
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9
github.com/davecgh/go-spew v1.1.1
github.com/go-sql-driver/mysql v1.6.0
github.com/google/go-cmp v0.5.7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -59,6 +59,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976 h1:vvvbSbmHS27Ayx0fAeFAR4chZoobj9RTYMlTIouSKgY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211208212222-82c441726976/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 h1:zvkJv+9Pxm1nnEMcKnShREt4qtduHKz4iw4AB4ul0Ao=
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/engine.go
Expand Up @@ -24,7 +24,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) *Compiler {
switch conf.Engine {
case config.EngineXLemon:
c.parser = sqlite.NewParser()
c.catalog = catalog.New("main")
c.catalog = sqlite.NewCatalog()
case config.EngineMySQL:
c.parser = dolphin.NewParser()
c.catalog = dolphin.NewCatalog()
Expand Down
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/count_star/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions internal/endtoend/testdata/count_star/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions internal/endtoend/testdata/count_star/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/endtoend/testdata/count_star/sqlite/query.sql
@@ -0,0 +1,5 @@
-- name: CountStarLower :one
SELECT count(*) FROM bar;

-- name: CountStarUpper :one
SELECT COUNT(*) FROM bar;
1 change: 1 addition & 0 deletions internal/endtoend/testdata/count_star/sqlite/schema.sql
@@ -0,0 +1 @@
CREATE TABLE bar (id BIGINT not null);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/count_star/sqlite/sqlc.json
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"name": "querytest",
"engine": "_lemon",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,2 @@
-- name: Placeholder :exec
SELECT 1;
@@ -0,0 +1,2 @@
CREATE TABLE foo (bar text, baz text);
ALTER TABLE foo DROP COLUMN bar;
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "_lemon",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/ddl_create_table/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions internal/endtoend/testdata/ddl_create_table/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions internal/endtoend/testdata/ddl_create_table/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/ddl_create_table/sqlite/query.sql
@@ -0,0 +1,2 @@
-- name: Placeholder :exec
SELECT 1;
@@ -0,0 +1 @@
CREATE TABLE venues (name text);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/ddl_create_table/sqlite/sqlc.json
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "_lemon",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
14 changes: 12 additions & 2 deletions internal/engine/sqlite/catalog.go
Expand Up @@ -3,6 +3,16 @@ package sqlite
import "github.com/kyleconroy/sqlc/internal/sql/catalog"

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

func newTestCatalog() *catalog.Catalog {
return catalog.New("main")
}
4 changes: 2 additions & 2 deletions internal/engine/sqlite/catalog_test.go
Expand Up @@ -239,13 +239,13 @@ func TestUpdate(t *testing.T) {
t.Fatal(err)
}

c := NewCatalog()
c := newTestCatalog()
if err := c.Build(stmts); err != nil {
t.Log(test.stmt)
t.Fatal(err)
}

e := NewCatalog()
e := newTestCatalog()
if test.s != nil {
var replaced bool
for i := range e.Schemas {
Expand Down

0 comments on commit 323187f

Please sign in to comment.