11 — Closures
Every link, at every level, stored as rows.
// Everyone with each boss above them, up to eight levels, kept as the // org chart is written. closure chain -> Above { from { e: entities.employee } link(from: e.key, to: e.manager, max_depth: 8, max_ancestors: 8) select(Above { employee: link.from, boss: link.to, depth: link.depth }) } // Everyone in a boss's organisation, at every level. query organisation(boss: EmployeeId) -> Page<StaffRow> { from { e: entities.employee c: join(queries.chain, on: c.employee == e.key) } where(c.boss == boss) select(StaffRow { name: e.name, depth: c.depth }) order_by(asc(c.depth), asc(e.name)) }