Skip to content

feat: More SQL Syntax Support for SQLite #1687

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

Merged
merged 24 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
95193d1
add test helper for SQLite
hakobera Jun 6, 2022
eb8ac20
[sqlite] support simple insert and select where clause
hakobera Jun 6, 2022
d9b4f40
[sqlite] Improve simple select syntax support
hakobera Jun 11, 2022
c2d7711
[sqlite] add support simple update statement
hakobera Jun 11, 2022
de09235
add booktest example for SQLite
hakobera Jun 11, 2022
a28eebd
[sqlite] support add column with NOT NULL constraint
hakobera Jun 12, 2022
e1a9886
add ondeck example for SQLite
hakobera Jun 12, 2022
87d0a41
Merge branch 'kyleconroy:main' into add-simple-crud-support-for-sqlite
hakobera Jun 12, 2022
4b558d4
regenerate example by sqlc 1.14
hakobera Jun 13, 2022
a9ee8b0
[sqlite] add endtoend test for alias
hakobera Jun 13, 2022
6de9932
[sqlite] support coalesce function
hakobera Jun 13, 2022
af12fa7
[sqlite] support 'bool' type
hakobera Jun 13, 2022
7649b8a
[sqlite] support create/drop view
hakobera Jun 13, 2022
df3db52
add endtoend test for SQLite
hakobera Jun 13, 2022
afd3943
[sqlite] update datatype mapping
hakobera Jun 13, 2022
ad2d9e3
[sqlite] support insert_select
hakobera Jun 15, 2022
b8aef7c
add endtoend test for SQLite
hakobera Jun 15, 2022
d2352bf
[sqlite] better select statement support
hakobera Jun 15, 2022
c205d59
add endtoend test for SQLite
hakobera Jun 15, 2022
d4f7fd4
Merge branch 'kyleconroy:main' into add-simple-crud-support-for-sqlite
hakobera Jun 15, 2022
bc7d672
[sqlite] support LIMIT and OFFSET
hakobera Jun 16, 2022
0844e65
add endtoend test for SQLite
hakobera Jun 16, 2022
e9d3a1f
add endtoend test for SQLite
hakobera Jun 17, 2022
9b444dd
[sqlite] support nested SELECT
hakobera Jun 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/authors/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
"out": "mysql"
}
}
},
{
"schema": "sqlite/schema.sql",
"queries": "sqlite/query.sql",
"engine": "_lemon",
"gen": {
"go": {
"package": "authors",
"out": "sqlite"
}
}
}
]
}
}
31 changes: 31 additions & 0 deletions examples/authors/sqlite/db.go

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

48 changes: 48 additions & 0 deletions examples/authors/sqlite/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build examples
// +build examples

package authors

import (
"context"
"database/sql"
"testing"

"github.com/kyleconroy/sqlc/internal/sqltest"
)

func TestAuthors(t *testing.T) {
sdb, cleanup := sqltest.SQLite(t, []string{"schema.sql"})
defer cleanup()

ctx := context.Background()
db := New(sdb)

// list all authors
authors, err := db.ListAuthors(ctx)
if err != nil {
t.Fatal(err)
}
t.Log(authors)

// create an author
result, err := db.CreateAuthor(ctx, CreateAuthorParams{
Name: "Brian Kernighan",
Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true},
})
if err != nil {
t.Fatal(err)
}
authorID, err := result.LastInsertId()
if err != nil {
t.Fatal(err)
}
t.Log(authorID)

// get the author we just inserted
fetchedAuthor, err := db.GetAuthor(ctx, authorID)
if err != nil {
t.Fatal(err)
}
t.Log(fetchedAuthor)
}
15 changes: 15 additions & 0 deletions examples/authors/sqlite/models.go

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

18 changes: 18 additions & 0 deletions examples/authors/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* name: GetAuthor :one */
SELECT * FROM authors
WHERE id = ? LIMIT 1;

/* name: ListAuthors :many */
SELECT * FROM authors
ORDER BY name;

/* name: CreateAuthor :execresult */
INSERT INTO authors (
name, bio
) VALUES (
?, ?
);

/* name: DeleteAuthor :exec */
DELETE FROM authors
WHERE id = ?;
78 changes: 78 additions & 0 deletions examples/authors/sqlite/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 examples/authors/sqlite/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id integer PRIMARY KEY AUTOINCREMENT,
name text NOT NULL,
bio text
);
9 changes: 8 additions & 1 deletion examples/booktest/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"schema": "mysql/schema.sql",
"queries": "mysql/query.sql",
"engine": "mysql"
},
{
"name": "booktest",
"path": "sqlite",
"schema": "sqlite/schema.sql",
"queries": "sqlite/query.sql",
"engine": "_lemon"
}
]
}
}
31 changes: 31 additions & 0 deletions examples/booktest/sqlite/db.go

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

Loading