MCPcopy
hub / github.com/ent/ent / TestSelector_SelectedColumn

Function TestSelector_SelectedColumn

dialect/sql/builder_test.go:2280–2316  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2278}
2279
2280func TestSelector_SelectedColumn(t *testing.T) {
2281 t.Run("MySQL", func(t *testing.T) {
2282 s := Select("*").From(Table("t1"))
2283 require.Empty(t, s.FindSelection("c"))
2284 s.Select("c")
2285 require.Equal(t, []string{"c"}, s.FindSelection("c"))
2286 s.Select(s.C("c"))
2287 require.Equal(t, []string{"`t1`.`c`"}, s.FindSelection("c"))
2288 s.AppendSelectAs(s.C("d"), "e")
2289 require.Equal(t, []string{"e"}, s.FindSelection("e"))
2290 require.Empty(t, s.FindSelection("d"))
2291 t2 := Table("t2").As("t2")
2292 s.Join(t2)
2293 s.Select(t2.C("e"), "t2.e", s.C("e"), "t1.e", "e")
2294 require.Equal(t, []string{"`t2`.`e`", "t2.e", "`t1`.`e`", "t1.e", "e"}, s.FindSelection("e"))
2295 s.AppendSelectExprAs(ExprFunc(func(b *Builder) {
2296 b.S("COUNT(").Ident("post_id").S(")")
2297 }), "post_count")
2298 require.Equal(t, []string{"post_count"}, s.FindSelection("post_count"))
2299 })
2300 t.Run("Postgres", func(t *testing.T) {
2301 b := Dialect(dialect.Postgres)
2302 s := b.Select("*").From(Table("t1"))
2303 require.Empty(t, s.FindSelection("c"))
2304 s.Select("c")
2305 require.Equal(t, []string{"c"}, s.FindSelection("c"))
2306 s.Select(s.C("c"))
2307 require.Equal(t, []string{`"t1"."c"`}, s.FindSelection("c"))
2308 s.AppendSelectAs(s.C("d"), "e")
2309 require.Equal(t, []string{"e"}, s.FindSelection("e"))
2310 require.Empty(t, s.FindSelection("d"))
2311 t2 := b.Table("t2").As("t2")
2312 s.Join(t2)
2313 s.Select(t2.C("e"), "t2.e", s.C("e"), "t1.e", "e")
2314 require.Equal(t, []string{`"t2"."e"`, "t2.e", `"t1"."e"`, "t1.e", "e"}, s.FindSelection("e"))
2315 })
2316}
2317
2318func TestColumnsHasPrefix(t *testing.T) {
2319 t.Run("MySQL", func(t *testing.T) {

Callers

nothing calls this directly

Calls 15

ExprFuncFunction · 0.85
DialectFunction · 0.85
RunMethod · 0.80
EmptyMethod · 0.80
FindSelectionMethod · 0.80
AppendSelectAsMethod · 0.80
AppendSelectExprAsMethod · 0.80
SMethod · 0.80
IdentMethod · 0.80
SelectFunction · 0.70
TableFunction · 0.70
CMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…