Getting started
If you would like just have a quick peak at a working project how a look at our playground folder on GitHub.
1. Setup Prisma project
Install the following node modules dependencies. See Prisma quick start guide. If you already have a Prisma project you can go ahead and simply install prisma-extension-bark only and skip to the next step.
npm i @prisma/client prisma-extension-bark
npm i -D prismaRun Prisma initialization command. (This will create new a folder named prisma with a prisma.schema file.)
npx prisma init2. Implement the required field on your model
In your schema.prisma file create a node model with the minimum required fields for Bark to work and the field you would like to have on this model. For more information on the model refer to Model Reference documentation.
// 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])
}3. Create migration
Run the following command to create a new database migration. For more information on this Prisma CLI command see Prisma documentation.
npx prisma migrate dev4. Extend Prisma Client with Bark
Nearly there! Create a new .js/.ts file and extend your Prisma client. Learn about Prisma Client extensions.
// 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' }Have a look at our Client Extension API documentation to discover what else you can do with Bark.
Last updated