paramFromFuncCall creates a param from sqlc.n?arg() calls return the parameter and whether the parameter name was specified a best guess as its "source" string representation (used for replacing this function call in the original SQL query)
(call *ast.FuncCall)
| 47 | // "source" string representation (used for replacing this function call in the |
| 48 | // original SQL query) |
| 49 | func paramFromFuncCall(call *ast.FuncCall) (named.Param, string) { |
| 50 | paramName, isConst := flatten(call.Args) |
| 51 | |
| 52 | // origName keeps track of how the parameter was specified in the source SQL |
| 53 | origName := paramName |
| 54 | if isConst { |
| 55 | origName = fmt.Sprintf("'%s'", paramName) |
| 56 | } |
| 57 | |
| 58 | var param named.Param |
| 59 | switch call.Func.Name { |
| 60 | case "narg": |
| 61 | param = named.NewUserNullableParam(paramName) |
| 62 | case "slice": |
| 63 | param = named.NewSqlcSlice(paramName) |
| 64 | default: |
| 65 | param = named.NewParam(paramName) |
| 66 | } |
| 67 | |
| 68 | // TODO: This code assumes that sqlc.arg(name) / sqlc.narg(name) is on a single line |
| 69 | // with no extraneous spaces (or any non-significant tokens for that matter) |
| 70 | // except between the function name and argument |
| 71 | funcName := call.Func.Schema + "." + call.Func.Name |
| 72 | spaces := "" |
| 73 | if call.Args != nil && len(call.Args.Items) > 0 { |
| 74 | leftParen := call.Args.Items[0].Pos() - 1 |
| 75 | spaces = strings.Repeat(" ", leftParen-call.Location-len(funcName)) |
| 76 | } |
| 77 | origText := fmt.Sprintf("%s%s(%s)", funcName, spaces, origName) |
| 78 | return param, origText |
| 79 | } |
| 80 | |
| 81 | func NamedParameters(engine config.Engine, raw *ast.RawStmt, numbs map[int]bool, dollar bool) (*ast.RawStmt, *named.ParamSet, []source.Edit) { |
| 82 | foundFunc := astutils.Search(raw, named.IsParamFunc) |
no test coverage detected