CRUD operations on prisma client
insert data with relations
// create
const user = await prisma.user.create({
data: {
name: 'abbas',
email: 'abbas@gmail.com'
},
userPrefrences: { // create other row with this
create: {
receiveEmails: true,
categories: { // if not exist to connect create it
connectOrCreate: {
where: { id: 3 },
create: { name: "Big Data" }
}
}
}
},
profile: { // connect created row with this
connect: {}
}
})
const users = await prisma.user.create({
data: {},
// returned result include only what in data, to include others
include: {
userPrefrences: true
},
// another option is select which enable us to exclude also main fields of row, we should use include or select not both
select: {
name: true,
userPrefrences: true,
another_relation: {
spesficFields: true
}
}
})