MCPcopy
hub / github.com/ent/ent / Modifier

Method Modifier

dialect/sql/sqlgraph/graph.go:592–622  ·  view source on GitHub ↗

Modifier returns a modifier function that limits the number of rows of the eager load query.

(partitionBy string, limit int, orderBy ...sql.Querier)

Source from the content-addressed store, hash-verified

590
591// Modifier returns a modifier function that limits the number of rows of the eager load query.
592func (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
624type (
625 // FieldSpec holds the information for updating a field

Callers 1

LimitNeighborsFunction · 0.95

Calls 15

DialectFunction · 0.92
RowNumberFunction · 0.92
LTEFunction · 0.92
PartitionByMethod · 0.80
NewMethod · 0.80
SetDistinctMethod · 0.80
AppendSelectExprAsMethod · 0.80
TableNameMethod · 0.80
UnqualifiedColumnsMethod · 0.80
DialectMethod · 0.65
WhereMethod · 0.65
CMethod · 0.65

Tested by

no test coverage detected