Bark
GitHub
  • Introduction
  • Getting started
  • Client Extension API reference
  • Model Reference
  • Changelog
  • Acknowledgement
Powered by GitBook
On this page
  • 1. Setup Prisma project
  • 2. Implement the required field on your model
  • 3. Create migration
  • 4. Extend Prisma Client with Bark
Edit on GitHub

Getting started

PreviousIntroductionNextClient Extension API reference

Last updated 1 year ago

If you would like just have a quick peak at a working project how a look at our .

1. Setup Prisma project

Install the following node modules dependencies. 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 prisma

Run Prisma initialization command. (This will create new a folder named prisma with a prisma.schema file.)

npx prisma init

2. 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 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

npx prisma migrate dev

4. Extend Prisma Client with Bark

// 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' }

Run the following command to create a new database migration. For more information on this Prisma CLI command .

Nearly there! Create a new .js/.ts file and extend your Prisma client. .

Have a look at our to discover what else you can do with Bark.

playground folder on GitHub
See Prisma quick start guide.
Model Reference
see Prisma documentation
Learn about Prisma Client extensions
Client Extension API documentation