Modifier returns a modifier function that limits the number of rows of the eager load query.
(partitionBy string, limit int, orderBy ...sql.Querier)
| 590 | |
| 591 | // Modifier returns a modifier function that limits the number of rows of the eager load query. |
| 592 | func (l *NeighborsLimit) Modifier(partitionBy string, limit int, orderBy ...sql.Querier) func(s *sql.Selector) { |
| 593 | return func(s *sql.Selector) { |
| 594 | var ( |
| 595 | d = sql.Dialect(s.Dialect()) |
| 596 | rn = sql.RowNumber().PartitionBy(partitionBy) |
| 597 | ) |
| 598 | switch { |
| 599 | case len(orderBy) > 0: |
| 600 | rn.OrderExpr(orderBy...) |
| 601 | case l.DefaultOrderField != "": |
| 602 | rn.OrderBy(l.DefaultOrderField) |
| 603 | default: |
| 604 | s.AddError(errors.New("no order terms provided for window function")) |
| 605 | return |
| 606 | } |
| 607 | s.SetDistinct(false) |
| 608 | with := d.With(l.SrcCTE). |
| 609 | As(s.Clone()). |
| 610 | With(l.LimitCTE). |
| 611 | As( |
| 612 | d.Select("*"). |
| 613 | AppendSelectExprAs(rn, l.RowNumber). |
| 614 | From(d.Table(l.SrcCTE)), |
| 615 | ) |
| 616 | t := d.Table(l.LimitCTE).As(s.TableName()) |
| 617 | *s = *d.Select(s.UnqualifiedColumns()...). |
| 618 | From(t). |
| 619 | Where(sql.LTE(t.C(l.RowNumber), limit)). |
| 620 | Prefix(with) |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | type ( |
| 625 | // FieldSpec holds the information for updating a field |
no test coverage detected