(columns []interface{})
| 345 | } |
| 346 | |
| 347 | func columnFragments(columns []interface{}) ([]exql.Fragment, []interface{}, error) { |
| 348 | f := make([]exql.Fragment, len(columns)) |
| 349 | args := []interface{}{} |
| 350 | |
| 351 | for i := range columns { |
| 352 | switch v := columns[i].(type) { |
| 353 | case hasPaginator: |
| 354 | p, err := v.Paginator() |
| 355 | if err != nil { |
| 356 | return nil, nil, err |
| 357 | } |
| 358 | |
| 359 | q, a := Preprocess(p.String(), p.Arguments()) |
| 360 | |
| 361 | f[i] = &exql.Raw{Value: "(" + q + ")"} |
| 362 | args = append(args, a...) |
| 363 | case isCompilable: |
| 364 | c, err := v.Compile() |
| 365 | if err != nil { |
| 366 | return nil, nil, err |
| 367 | } |
| 368 | q, a := Preprocess(c, v.Arguments()) |
| 369 | if _, ok := v.(db.Selector); ok { |
| 370 | q = "(" + q + ")" |
| 371 | } |
| 372 | f[i] = &exql.Raw{Value: q} |
| 373 | args = append(args, a...) |
| 374 | case *adapter.FuncExpr: |
| 375 | fnName, fnArgs := v.Name(), v.Arguments() |
| 376 | if len(fnArgs) == 0 { |
| 377 | fnName = fnName + "()" |
| 378 | } else { |
| 379 | fnName = fnName + "(?" + strings.Repeat(", ?", len(fnArgs)-1) + ")" |
| 380 | } |
| 381 | fnName, fnArgs = Preprocess(fnName, fnArgs) |
| 382 | f[i] = &exql.Raw{Value: fnName} |
| 383 | args = append(args, fnArgs...) |
| 384 | case *adapter.RawExpr: |
| 385 | q, a := Preprocess(v.Raw(), v.Arguments()) |
| 386 | f[i] = &exql.Raw{Value: q} |
| 387 | args = append(args, a...) |
| 388 | case exql.Fragment: |
| 389 | f[i] = v |
| 390 | case string: |
| 391 | f[i] = exql.ColumnWithName(v) |
| 392 | case fmt.Stringer: |
| 393 | f[i] = exql.ColumnWithName(v.String()) |
| 394 | default: |
| 395 | var err error |
| 396 | f[i], err = exql.NewRawValue(columns[i]) |
| 397 | if err != nil { |
| 398 | return nil, nil, fmt.Errorf("unexpected argument type %T for Select() argument: %w", v, err) |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | return f, args, nil |
| 403 | } |
| 404 |
no test coverage detected