Skip to content

Commit

Permalink
engine/mysql: Add support for LIKE (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy committed Sep 7, 2021
1 parent 0143129 commit e178fdd
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 1 deletion.
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/pattern_matching/mysql/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/pattern_matching/mysql/go/models.go

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

36 changes: 36 additions & 0 deletions internal/endtoend/testdata/pattern_matching/mysql/go/query.sql.go

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

4 changes: 4 additions & 0 deletions internal/endtoend/testdata/pattern_matching/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE pet (name text);

-- name: PetsByName :many
SELECT * FROM pet WHERE name LIKE ?;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/pattern_matching/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "mysql",
"path": "go",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
29 changes: 29 additions & 0 deletions internal/endtoend/testdata/pattern_matching/postgresql/go/db.go

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE pet (name text);

-- name: PetsByName :many
SELECT * FROM pet WHERE name LIKE $1;
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/pattern_matching/postgresql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "postgresql",
"path": "go",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
11 changes: 10 additions & 1 deletion internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,16 @@ func (c *cc) convertPatternInExpr(n *pcast.PatternInExpr) ast.Node {
}

func (c *cc) convertPatternLikeExpr(n *pcast.PatternLikeExpr) ast.Node {
return todo(n)
return &ast.A_Expr{
Kind: ast.A_Expr_Kind(9),
Name: &ast.List{
Items: []ast.Node{
&ast.String{Str: "~~"},
},
},
Lexpr: c.convert(n.Expr),
Rexpr: c.convert(n.Pattern),
}
}

func (c *cc) convertPatternRegexpExpr(n *pcast.PatternRegexpExpr) ast.Node {
Expand Down

0 comments on commit e178fdd

Please sign in to comment.