Skip to content

Commit

Permalink
sqlite: supported between expr (#1958) (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdoker18 authored Nov 30, 2022
1 parent c8c0233 commit 9e13aa7
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/between_args/sqlite/go/db.go

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

12 changes: 12 additions & 0 deletions internal/endtoend/testdata/between_args/sqlite/go/models.go

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

112 changes: 112 additions & 0 deletions internal/endtoend/testdata/between_args/sqlite/go/query.sql.go

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

19 changes: 19 additions & 0 deletions internal/endtoend/testdata/between_args/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE products (
name TEXT NOT NULL,
price INT NOT NULL
);

-- name: GetBetweenPrices :many
SELECT *
FROM products
WHERE price BETWEEN ? AND ?;

-- name: GetBetweenPricesTable :many
SELECT *
FROM products
WHERE products.price BETWEEN ? AND ?;

-- name: GetBetweenPricesTableAlias :many
SELECT *
FROM products as p
WHERE p.price BETWEEN ? AND ?;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/between_args/sqlite/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "sqlite",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
13 changes: 13 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,16 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node {
}
}

func (c *cc) convertBetweenExpr(n *parser.Expr_betweenContext) ast.Node {
return &ast.BetweenExpr{
Expr: c.convert(n.Expr(0)),
Left: c.convert(n.Expr(1)),
Right: c.convert(n.Expr(2)),
Location: n.GetStart().GetStart(),
Not: n.NOT_() != nil,
}
}

func (c *cc) convert(node node) ast.Node {
switch n := node.(type) {

Expand Down Expand Up @@ -815,6 +825,9 @@ func (c *cc) convert(node node) ast.Node {
case *parser.Expr_in_selectContext:
return c.convertInSelectNode(n)

case *parser.Expr_betweenContext:
return c.convertBetweenExpr(n)

case *parser.Factored_select_stmtContext:
// TODO: need to handle this
return todo(n)
Expand Down

0 comments on commit 9e13aa7

Please sign in to comment.