Skip to content

Commit 5520677

Browse files
authored
dolphi: Add list of builtin functions (#795)
1 parent e1f1d44 commit 5520677

File tree

9 files changed

+2074
-35
lines changed

9 files changed

+2074
-35
lines changed

internal/endtoend/testdata/count_star/mysql/go/query.sql.go

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
CREATE TABLE bar (id serial not null);
22

3-
-- name: CountStar :one
3+
-- name: CountStarLower :one
44
SELECT count(*) FROM bar;
5+
6+
-- name: CountStarUpper :one
7+
SELECT COUNT(*) FROM bar;

internal/endtoend/testdata/count_star/postgresql/go/query.sql.go

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
CREATE TABLE bar (id serial not null);
22

3-
-- name: CountStar :one
3+
-- name: CountStarLower :one
44
SELECT count(*) FROM bar;
5+
6+
-- name: CountStarUpper :one
7+
SELECT COUNT(*) FROM bar;

internal/engine/dolphin/catalog.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dolphin
22

33
import (
4-
"github.com/kyleconroy/sqlc/internal/sql/ast"
54
"github.com/kyleconroy/sqlc/internal/sql/catalog"
65
)
76

@@ -10,25 +9,7 @@ func NewCatalog() *catalog.Catalog {
109
return &catalog.Catalog{
1110
DefaultSchema: def,
1211
Schemas: []*catalog.Schema{
13-
&catalog.Schema{
14-
Name: def,
15-
Funcs: []*catalog.Function{
16-
{
17-
Name: "count",
18-
Args: []*catalog.Argument{
19-
{
20-
Type: &ast.TypeName{Name: "any"},
21-
},
22-
},
23-
ReturnType: &ast.TypeName{Name: "bigint"},
24-
},
25-
{
26-
Name: "count",
27-
Args: []*catalog.Argument{},
28-
ReturnType: &ast.TypeName{Name: "bigint"},
29-
},
30-
},
31-
},
12+
defaultSchema(def),
3213
},
3314
Extensions: map[string]struct{}{},
3415
}

internal/engine/dolphin/convert.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dolphin
33
import (
44
"fmt"
55
"log"
6+
"strings"
67

78
pcast "github.com/pingcap/parser/ast"
89
"github.com/pingcap/parser/opcode"
@@ -322,7 +323,7 @@ func (c *cc) convertFieldList(n *pcast.FieldList) *ast.List {
322323

323324
func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) *ast.FuncCall {
324325
schema := n.Schema.String()
325-
name := n.FnName.String()
326+
name := strings.ToLower(n.FnName.String())
326327

327328
// TODO: Deprecate the usage of Funcname
328329
items := []ast.Node{}
@@ -494,14 +495,15 @@ func (c *cc) convertAdminStmt(n *pcast.AdminStmt) ast.Node {
494495
}
495496

496497
func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall {
498+
name := strings.ToLower(n.F)
497499
fn := &ast.FuncCall{
498500
Func: &ast.FuncName{
499-
Name: n.F,
501+
Name: name,
500502
},
501503
Funcname: &ast.List{
502504
Items: []ast.Node{
503505
&ast.String{
504-
Str: n.F,
506+
Str: name,
505507
},
506508
},
507509
},

0 commit comments

Comments
 (0)