MCPcopy Index your code
hub / github.com/ent/ent / countAlias

Function countAlias

dialect/sql/sqlgraph/graph.go:356–376  ·  view source on GitHub ↗

countAlias returns the alias to use for the count column.

(q *sql.Selector, s *Step, opt *sql.OrderTermOptions)

Source from the content-addressed store, hash-verified

354
355// countAlias returns the alias to use for the count column.
356func countAlias(q *sql.Selector, s *Step, opt *sql.OrderTermOptions) string {
357 if opt.As != "" {
358 return opt.As
359 }
360 selected := make(map[string]struct{})
361 for _, c := range q.SelectedColumns() {
362 selected[c] = struct{}{}
363 }
364 column := fmt.Sprintf("count_%s", s.To.Table)
365 // If the column was already selected,
366 // try to find a free alias.
367 if _, ok := selected[column]; ok {
368 for i := 1; i <= 5; i++ {
369 ci := fmt.Sprintf("%s_%d", column, i)
370 if _, ok := selected[ci]; !ok {
371 return ci
372 }
373 }
374 }
375 return column
376}
377
378// OrderByNeighborsCount appends ordering based on the number of neighbors.
379// For example, order users by their number of posts.

Callers 1

OrderByNeighborsCountFunction · 0.85

Calls 1

SelectedColumnsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…