forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc_call.go
More file actions
52 lines (44 loc) · 1 KB
/
func_call.go
File metadata and controls
52 lines (44 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package validate
import (
"errors"
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/sql/ast"
"github.com/sqlc-dev/sqlc/internal/sql/astutils"
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
)
type funcCallVisitor struct {
catalog *catalog.Catalog
settings config.CombinedSettings
err error
}
func (v *funcCallVisitor) Visit(node ast.Node) astutils.Visitor {
if v.err != nil {
return nil
}
call, ok := node.(*ast.FuncCall)
if !ok {
return v
}
fn := call.Func
if fn == nil {
return v
}
if fn.Schema == "sqlc" {
return nil
}
fun, err := v.catalog.ResolveFuncCall(call)
if fun != nil {
return v
}
if errors.Is(err, sqlerr.NotFound) && !v.settings.Package.StrictFunctionChecks {
return v
}
v.err = err
return nil
}
func FuncCall(c *catalog.Catalog, cs config.CombinedSettings, n ast.Node) error {
visitor := funcCallVisitor{catalog: c, settings: cs}
astutils.Walk(&visitor, n)
return visitor.err
}