Recursive CTE Query Builder
Component Detail
Infrastructure
medium complexity
backend
0
Dependencies
2
Dependents
1
Entities
0
Integrations
Description
Utility for constructing parameterized recursive Common Table Expression SQL fragments in PostgreSQL for arbitrary-depth tree traversal. Ensures query safety, depth bounding, and consistent result mapping across all hierarchy traversal operations.
recursive-cte-query-builder
Responsibilities
- Generate safe parameterized recursive CTE SQL for ancestor and descendant queries
- Enforce a configurable maximum recursion depth to prevent runaway queries on corrupted data
- Provide typed row-to-domain-object mappers for organization tree results
Interfaces
buildAncestorCTE(anchorId: string, maxDepth: number): SqlFragment
buildDescendantCTE(anchorId: string, maxDepth: number): SqlFragment
mapRowToOrganizationNode(row: Record<string, unknown>): OrganizationNode
Relationships
Dependents (2)
Components that depend on this component