Files
ent/examples/fs
Roman Maklakov 84070a0f07 entc/gen: add ctx in client.BeginTx (#2260)
* doc: fix docker-compose up command(#2253)

* entc/gen: add ctx in TxBegin & run go generate (#2253)

* entc/integration: add tests for TxBegin Commit and Rollback (#2253)

* entc/integration: uncomment accidentally commented code(#2253)

* entc/integration: fixes after code-review (#2253)

* entc/integration: remove blank lines, code-review (#2253)

* examples: run code gen  (#2253)
2022-01-12 14:28:55 +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