MCPcopy
hub / github.com/sqlc-dev/sqlc / Visit

Method Visit

internal/sql/validate/param_style.go:15–62  ·  view source on GitHub ↗
(node ast.Node)

Source from the content-addressed store, hash-verified

13}
14
15func (v *sqlcFuncVisitor) Visit(node ast.Node) astutils.Visitor {
16 if v.err != nil {
17 return nil
18 }
19
20 call, ok := node.(*ast.FuncCall)
21 if !ok {
22 return v
23 }
24 fn := call.Func
25 if fn == nil {
26 return v
27 }
28
29 // Custom validation for sqlc.arg, sqlc.narg and sqlc.slice
30 // TODO: Replace this once type-checking is implemented
31 if fn.Schema == "sqlc" {
32 if !(fn.Name == "arg" || fn.Name == "narg" || fn.Name == "slice" || fn.Name == "embed") {
33 v.err = sqlerr.FunctionNotFound("sqlc." + fn.Name)
34 return nil
35 }
36
37 if len(call.Args.Items) != 1 {
38 v.err = &sqlerr.Error{
39 Message: fmt.Sprintf("expected 1 parameter to sqlc.%s; got %d", fn.Name, len(call.Args.Items)),
40 Location: call.Pos(),
41 }
42 return nil
43 }
44
45 switch n := call.Args.Items[0].(type) {
46 case *ast.A_Const:
47 case *ast.ColumnRef:
48 default:
49 v.err = &sqlerr.Error{
50 Message: fmt.Sprintf("expected parameter to sqlc.%s to be string or reference; got %T", fn.Name, n),
51 Location: call.Pos(),
52 }
53 return nil
54 }
55
56 // If we have sqlc.arg or sqlc.narg, there is no need to resolve the function call.
57 // It won't resolve anyway, sinc it is not a real function.
58 return nil
59 }
60
61 return nil
62}
63
64func SqlcFunctions(n ast.Node) error {
65 visitor := sqlcFuncVisitor{}

Callers

nothing calls this directly

Calls 2

FunctionNotFoundFunction · 0.92
PosMethod · 0.65

Tested by

no test coverage detected