Files
ent/examples/fs
Nicholas Anderson 896f2b202d entc/gen: update NotSingularError godoc (#2274)
* fix: update only/onlyID comments

this patch updates the Only/OnlyID methods in the builder template from:

> // Returns a *NotSingularError when exactly one {{ $.Name }} entity is not found.
to
> // Returns a *NotSingularError when more than exactly one {{ $.Name }} ID is found.

in an effort to be more explicit in the explanation of the behavior of the methods.

* fix: update wording to be more concise from suggestion

Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>

* fix: update Only wording to be more concicse

* fix: generate new files

Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>
2022-01-23 19:07:10 +02:00
..

Recursive Traversal Using CTE

In this example, we create a file system with a tree structure, and want to query all "undeleted" files. A file is considered as "deleted", if it's marked as "deleted" (a bool field), or any of its parents is marked as "deleted".

Given the following tree structure:

a/
├─ b/
│  ├─ ba
│  ├─ bb
│  └─ bc (deleted)
├─ c/ (deleted)
│  ├─ ca
│  └─ cb
└─ d (deleted)

Query "undeleted" files should return the following structure:

a/
└─ b/
   ├─ ba
   └─ bb

As you can see, in order to check if "cb" (or "ca") is "deleted", we need to "look behind" recursively until we find a "deleted" parent, or reach the root ("a").

Generate Assets

go generate ./...

Run Example

go test