| 409 | } |
| 410 | |
| 411 | func (_q *CustomTypeQuery) sqlQuery(ctx context.Context) *sql.Selector { |
| 412 | builder := sql.Dialect(_q.driver.Dialect()) |
| 413 | t1 := builder.Table(customtype.Table) |
| 414 | columns := _q.ctx.Fields |
| 415 | if len(columns) == 0 { |
| 416 | columns = customtype.Columns |
| 417 | } |
| 418 | selector := builder.Select(t1.Columns(columns...)...).From(t1) |
| 419 | if _q.sql != nil { |
| 420 | selector = _q.sql |
| 421 | selector.Select(selector.Columns(columns...)...) |
| 422 | } |
| 423 | if _q.ctx.Unique != nil && *_q.ctx.Unique { |
| 424 | selector.Distinct() |
| 425 | } |
| 426 | for _, p := range _q.predicates { |
| 427 | p(selector) |
| 428 | } |
| 429 | for _, p := range _q.order { |
| 430 | p(selector) |
| 431 | } |
| 432 | if offset := _q.ctx.Offset; offset != nil { |
| 433 | // limit is mandatory for offset clause. We start |
| 434 | // with default value, and override it below if needed. |
| 435 | selector.Offset(*offset).Limit(math.MaxInt32) |
| 436 | } |
| 437 | if limit := _q.ctx.Limit; limit != nil { |
| 438 | selector.Limit(*limit) |
| 439 | } |
| 440 | return selector |
| 441 | } |
| 442 | |
| 443 | // CustomTypeGroupBy is the group-by builder for CustomType entities. |
| 444 | type CustomTypeGroupBy struct { |