MCPcopy
hub / github.com/upper/db / expandArgument

Function expandArgument

internal/sqlbuilder/convert.go:56–91  ·  view source on GitHub ↗
(arg interface{})

Source from the content-addressed store, hash-verified

54}
55
56func expandArgument(arg interface{}) ([]byte, []interface{}) {
57 values, isSlice := toInterfaceArguments(arg)
58
59 if isSlice {
60 if len(values) == 0 {
61 return []byte("(NULL)"), nil
62 }
63 buf := bytes.Repeat([]byte(" ?,"), len(values))
64 buf[0] = '('
65 buf[len(buf)-1] = ')'
66 return buf, values
67 }
68
69 if len(values) == 1 {
70 switch t := arg.(type) {
71 case *adapter.RawExpr:
72 return expandQuery([]byte(t.Raw()), t.Arguments())
73 case hasPaginator:
74 p, err := t.Paginator()
75 if err == nil {
76 return append([]byte{'('}, append([]byte(p.String()), ')')...), p.Arguments()
77 }
78 panic(err.Error())
79 case isCompilable:
80 s, err := t.Compile()
81 if err == nil {
82 return append([]byte{'('}, append([]byte(s), ')')...), t.Arguments()
83 }
84 panic(err.Error())
85 }
86 } else if len(values) == 0 {
87 return []byte("NULL"), nil
88 }
89
90 return nil, []interface{}{arg}
91}
92
93// toInterfaceArguments converts the given value into an array of interfaces.
94func toInterfaceArguments(value interface{}) (args []interface{}, isSlice bool) {

Callers 1

expandQueryFunction · 0.85

Calls 8

toInterfaceArgumentsFunction · 0.85
expandQueryFunction · 0.85
RawMethod · 0.80
ArgumentsMethod · 0.65
PaginatorMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.65
CompileMethod · 0.65

Tested by

no test coverage detected