Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start filling out SQLite support #1410

Merged
merged 25 commits into from Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

32 changes: 32 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