Database Overview

By default, Blitz uses Prisma 2 which is a strongly typed database client.

Prisma 2 is not required for Blitz. You can use anything you want, such as Mongo, TypeORM, etc.

Read the Prisma documentation here

Add a Database Table

  1. Open db/schema.prisma and add your model(s) like as follows:
model Project {
id Int @default(autoincrement()) @id
name String
tasks Task[]
}
model Task {
id Int @default(autoincrement()) @id
name String
project Project @relation(fields: [projectId], references: [id])
projectId Int
}

If you need,

reference the Prisma Schema documentation

  1. Then run blitz db migrate in your terminal to apply the changes
  2. Now you can import db from db/index.ts and create a model like this:
    • db.project.create({data: {name: 'Hello'}})
Idea for improving this page?Edit it on Github