MCPcopy
hub / github.com/ent/ent / FindSelection

Method FindSelection

dialect/sql/builder.go:1814–1848  ·  view source on GitHub ↗

FindSelection returns all occurrences in the selection that match the given column name. For example, for column "a" the following match: a, "a", "t"."a", "t"."b" AS "a".

(name string)

Source from the content-addressed store, hash-verified

1812// FindSelection returns all occurrences in the selection that match the given column name.
1813// For example, for column "a" the following match: a, "a", "t"."a", "t"."b" AS "a".
1814func (s *Selector) FindSelection(name string) (matches []string) {
1815 matchC := func(qualified string) bool {
1816 switch ident, pg := s.isIdent(qualified), s.postgres(); {
1817 case !ident:
1818 if i := strings.IndexRune(qualified, '.'); i > 0 {
1819 return qualified[i+1:] == name
1820 }
1821 case ident && pg:
1822 if i := strings.Index(qualified, `"."`); i > 0 {
1823 return s.unquote(qualified[i+2:]) == name
1824 }
1825 case ident:
1826 if i := strings.Index(qualified, "`.`"); i > 0 {
1827 return s.unquote(qualified[i+2:]) == name
1828 }
1829 }
1830 return false
1831 }
1832 for _, c := range s.selection {
1833 switch {
1834 // Match aliases.
1835 case c.as != "":
1836 if ident := s.isIdent(c.as); !ident && c.as == name || ident && s.unquote(c.as) == name {
1837 matches = append(matches, c.as)
1838 }
1839 // Match qualified columns.
1840 case c.c != "" && s.isQualified(c.c) && matchC(c.c):
1841 matches = append(matches, c.c)
1842 // Match unqualified columns.
1843 case c.c != "" && (c.c == name || s.isIdent(c.c) && s.unquote(c.c) == name):
1844 matches = append(matches, c.c)
1845 }
1846 }
1847 return matches
1848}
1849
1850// SelectedColumns returns the selected columns in the Selector.
1851func (s *Selector) SelectedColumns() []string {

Callers 1

Calls 5

isIdentMethod · 0.80
postgresMethod · 0.80
unquoteMethod · 0.80
isQualifiedMethod · 0.80
IndexMethod · 0.45

Tested by 1