This quickstart guide will help you get up and running with Prisma ORM in just a few minutes. You’ll set up Prisma, create a simple schema, and run your first queries.
This guide uses SQLite for simplicity. For production applications, consider using PostgreSQL, MySQL, or another production database.
Create a prisma directory with a schema.prisma file:
mkdir prisma
Create prisma/schema.prisma with the following content:
prisma/schema.prisma
generator client { provider = "prisma-client" output = "../generated/client"}datasource db { provider = "sqlite"}model User { id String @id @default(uuid()) email String @unique name String? posts Post[]}model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User? @relation(fields: [authorId], references: [id]) authorId String?}
This schema defines two models: User and Post, with a one-to-many relationship. The @id, @default, and @relation attributes define the database structure.
For SQLite, the connection URL is a file path relative to the config file. For other databases, you’d use a connection string.
Prisma 7 uses prisma.config.ts for configuration instead of environment variables in the schema file. This provides better type safety and flexibility.
import { PrismaClient } from './generated/client'import { PrismaSqlite } from '@prisma/adapter-better-sqlite3'import Database from 'better-sqlite3'async function main() { // Initialize the database adapter const db = new Database('dev.db') const adapter = new PrismaSqlite(db) const prisma = new PrismaClient({ adapter }) // Create a new user with a post const user = await prisma.user.create({ data: { name: 'Alice', email: 'alice@prisma.io', posts: { create: { title: 'Hello World', content: 'This is my first post!', published: true, }, }, }, }) console.log('Created user:', user) // Query all users with their posts const allUsers = await prisma.user.findMany({ include: { posts: true, }, }) console.log('All users:', JSON.stringify(allUsers, null, 2)) // Close the database connection db.close()}main() .catch((e) => { console.error(e) process.exit(1) })