https://www.prisma.io/docs/concepts/components/prisma-client/crud
- create( create a single record )
const user = await prisma.user.create({
data: {
email: 'elsa@prisma.io',
name: 'Elsa Prisma',
},
})
- createMany ( create multiple records )
const createMany = await prisma.user.createMany({
data: [
{ name: 'Bob', email: 'bob@prisma.io' },
{ name: 'Bobo', email: 'bob@prisma.io' }, // Duplicate unique key!
{ name: 'Yewande', email: 'yewande@prisma.io' },
{ name: 'Angelique', email: 'angelique@prisma.io' },
],
skipDuplicates: true, // Skip 'Bobo'
})
- Create records and connect or create related records
- Read
- Get record by ID or unique identifier
- Get record by compound ID or compound unique identifier
- Get all records
- Get the first record that matches a specific criteria
- Get a filtered list of records
- Filter by a single field value
- Filter by multiple field values
- Filter by related record field values
- Select a subset of fields
- Select a subset of related record fields
- Select distinct field values
- Include related records
- Include a filtered list of relations
- Update
- Update a single record
- Update multiple records
- upsert ( update or create records )
const upsertUser = await prisma.user.upsert({
where: {
email: 'viola@prisma.io',
},
update: {
name: 'Viola the Magnificent',
},
create: {
email: 'viola@prisma.io',
name: 'Viola the Magnificent',
},
})
- Update a number field
- Connect and disconnect related records
- Delete
- Delete a single record
- Delete multiple records
- Delete all records
- Cascading deletes (deleting related records)
- Delete all records from all tables
- Deleting all data with deleteMany
- Deleting all data with raw SQL / TRUNCATE
- Deleting all records with Prisma Migrate
- Advanced query examples
- Create a deeply nested tree of records