(arg interface{})
| 54 | } |
| 55 | |
| 56 | func 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. |
| 94 | func toInterfaceArguments(value interface{}) (args []interface{}, isSlice bool) { |
no test coverage detected