prisma-ltree
PostgreSQL ltree extension for Prisma 8
PostgreSQL ltree stores hierarchical tree data. This extension pack adds typed codecs, query operators, and a baseline migration so you can query that data from Prisma 8 without raw SQL.
Author your contract in either lane. Both emit the same compiled result:
- PSL:
contract.prismawithltree.Ltree()andltree.LtreeArray() - TypeScript:
contract.tswithdefineContractandltree()/ltreeArray()
See Author ltree columns for side-by-side examples. The Get started guide covers install, runtime wiring, migrations, and your first queries.
Indexes and sorting
GiST required for ancestor, descendant, and pattern queries: add a GiST index on path columns (@@index([path], type: "gist")). Without it, those filters still run as sequential scans.
B-tree comparison and orderBy come from the codec traits equality and order on pg/ltree@1. This pack does not add < / > methods. See Sort and compare paths.
The ltree type
The PostgreSQL ltree type stores dot-separated path labels (e.g. Top.Science.Astronomy). It fits org hierarchies, category trees, taxonomies, and any model where ancestor or descendant queries matter.
Query operations
- Hierarchy operators: ancestor and descendant checks (
isAncestorOf,isDescendantOf) - Pattern matching operators:
lqueryandltxtquerypatterns - Scalar path functions:
nlevel,subltree,subpath,indexOf - Concatenation and conversion:
concat,concatText,prependText,toText,toLtree - Lowest common ancestor:
lcaandlcaAll - Array first-match operators: first matching path in
ltree[] - Array boolean operators: existence checks on
ltree[]