MCPcopy
hub / github.com/ent/ent / TestSelector_SetOperatorWithRecursive

Function TestSelector_SetOperatorWithRecursive

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

Source from the content-addressed store, hash-verified

1661}
1662
1663func TestSelector_SetOperatorWithRecursive(t *testing.T) {
1664 t1, t2, t3 := Table("files"), Table("files"), Table("path")
1665 n := Queries{
1666 WithRecursive("path", "id", "name", "parent_id").
1667 As(Select(t1.Columns("id", "name", "parent_id")...).
1668 From(t1).
1669 Where(
1670 And(
1671 IsNull(t1.C("parent_id")),
1672 EQ(t1.C("deleted"), false),
1673 ),
1674 ).
1675 UnionAll(
1676 Select(t2.Columns("id", "name", "parent_id")...).
1677 From(t2).
1678 Join(t3).
1679 On(t2.C("parent_id"), t3.C("id")).
1680 Where(
1681 EQ(t2.C("deleted"), false),
1682 ),
1683 ),
1684 ),
1685 Select(t3.Columns("id", "name", "parent_id")...).
1686 From(t3),
1687 }
1688 query, args := n.Query()
1689 require.Equal(t, "WITH RECURSIVE `path`(`id`, `name`, `parent_id`) AS (SELECT `files`.`id`, `files`.`name`, `files`.`parent_id` FROM `files` WHERE `files`.`parent_id` IS NULL AND NOT `files`.`deleted` UNION ALL SELECT `files`.`id`, `files`.`name`, `files`.`parent_id` FROM `files` JOIN `path` AS `t1` ON `files`.`parent_id` = `t1`.`id` WHERE NOT `files`.`deleted`) SELECT `t1`.`id`, `t1`.`name`, `t1`.`parent_id` FROM `path` AS `t1`", query)
1690 require.Nil(t, args)
1691}
1692
1693func TestBuilderContext(t *testing.T) {
1694 type key string

Callers

nothing calls this directly

Calls 15

QueryMethod · 0.95
WithRecursiveFunction · 0.85
IsNullFunction · 0.85
UnionAllMethod · 0.80
OnMethod · 0.80
TableFunction · 0.70
SelectFunction · 0.70
AndFunction · 0.70
EQFunction · 0.70
WhereMethod · 0.65
ColumnsMethod · 0.65
CMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…