prisma-extension-bark
is an implementation of the Materialized Path pattern that allows you to easily create and interact with tree structures in Prisma.
See the documentation to learn more.
For more context please refer to our Getting Started guide.
npm i @prisma/client prisma-extension-bark
npm i -D prisma
npx prisma init
// prisma/schema.prisma
model node {
// Extension's internal fields
id Int @id @default(autoincrement())
path String @unique
depth Int
numchild Int @default(0)
// Your fields go here...
name String
@@index([path])
}
npx prisma migrate dev
// index.js
import { PrismaClient } from '@prisma/client'
import { withBark } from 'prisma-extension-bark'
const xprisma = new PrismaClient().$extends(withBark({ modelNames: ['node'] }))
const myNewRootNode = await xprisma.node.createRoot({ data: { name: 'My new root' } })
// { id: 1, path: '0001', depth: 1, numchild: 0, name: 'My new root' }