| 495 | } |
| 496 | |
| 497 | func (gcq *GitCommitQuery) sqlQuery(ctx context.Context) *sql.Selector { |
| 498 | builder := sql.Dialect(gcq.driver.Dialect()) |
| 499 | t1 := builder.Table(gitcommit.Table) |
| 500 | columns := gcq.ctx.Fields |
| 501 | if len(columns) == 0 { |
| 502 | columns = gitcommit.Columns |
| 503 | } |
| 504 | selector := builder.Select(t1.Columns(columns...)...).From(t1) |
| 505 | if gcq.sql != nil { |
| 506 | selector = gcq.sql |
| 507 | selector.Select(selector.Columns(columns...)...) |
| 508 | } |
| 509 | if gcq.ctx.Unique != nil && *gcq.ctx.Unique { |
| 510 | selector.Distinct() |
| 511 | } |
| 512 | for _, m := range gcq.modifiers { |
| 513 | m(selector) |
| 514 | } |
| 515 | for _, p := range gcq.predicates { |
| 516 | p(selector) |
| 517 | } |
| 518 | for _, p := range gcq.order { |
| 519 | p(selector) |
| 520 | } |
| 521 | if offset := gcq.ctx.Offset; offset != nil { |
| 522 | // limit is mandatory for offset clause. We start |
| 523 | // with default value, and override it below if needed. |
| 524 | selector.Offset(*offset).Limit(math.MaxInt32) |
| 525 | } |
| 526 | if limit := gcq.ctx.Limit; limit != nil { |
| 527 | selector.Limit(*limit) |
| 528 | } |
| 529 | return selector |
| 530 | } |
| 531 | |
| 532 | // ForUpdate locks the selected rows against concurrent updates, and prevent them from being |
| 533 | // updated, deleted or "selected ... for update" by other sessions, until the transaction is |