8000 feat(mysql): Implement cast function parser by RadhiFadlillah · Pull Request #2473 · sqlc-dev/sqlc · GitHub
[go: up one dir, main page]

Skip to content

feat(mysql): Implement cast function parser #2473

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 3 commits into from
Jul 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
10000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add nil check in parseRelation
  • Loading branch information
RadhiFadlillah committed Jul 29, 2023
commit 928e64bedd0b7d13d70937efb2ea312510598038
29 changes: 20 additions & 9 deletions internal/compiler/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ type Relation struct {
}

func parseRelation(node ast.Node) (*Relation, error) {
if n, ok := node.(*ast.Boolean); ok && n != nil {
switch n := node.(type) {
case *ast.Boolean:
if n == nil {
return nil, fmt.Errorf("unexpected nil in %T node", n)
}
return &Relation{Name: "bool"}, nil
}

if n, ok := node.(*ast.List); ok && n != nil {
case *ast.List:
if n == nil {
return nil, fmt.Errorf("unexpected nil in %T node", n)
}
parts := stringSlice(n)
switch len(parts) {
case 1:
Expand All @@ -56,9 +62,11 @@ func parseRelation(node ast.Node) (*Relation, error) {
default:
return nil, fmt.Errorf("invalid name: %s", astutils.Join(n, "."))
}
}

if n, ok := node.(*ast.RangeVar); ok && n != nil {
case *ast.RangeVar:
if n == nil {
return nil, fmt.Errorf("unexpected nil in %T node", n)
}
name := Relation{}
if n.Catalogname != nil {
name.Catalog = *n.Catalogname
Expand All @@ -70,17 +78,20 @@ func parseRelation(node ast.Node) (*Relation, error) {
name.Name = *n.Relname
}
return &name, nil
}

if n, ok := node.(*ast.TypeName); ok && n != nil {
case *ast.TypeName:
if n == nil {
return nil, fmt.Errorf("unexpected nil in %T node", n)
}
if n.Names != nil {
return parseRelation(n.Names)
} else {
return &Relation{Name: n.Name}, nil
}
}

return nil, fmt.Errorf("unexpected node type: %T", node)
default:
return nil, fmt.Errorf("unexpected node type: %T", node)
}
}

func ParseTableName(node ast.Node) (*ast.TableName, error) {
Expand Down
0