Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skolhustick/ee6c64f8b32caa2d6adf0c41517fea03 to your computer and use it in GitHub Desktop.
Save skolhustick/ee6c64f8b32caa2d6adf0c41517fea03 to your computer and use it in GitHub Desktop.
next-js-prisma-orm-mongodb-prisma:user.js
// /prisma/user.js
import prisma from './prisma'
// READ
export const getAllUsers = async () => {
const users = await prisma.user.findMany({})
return users
}
export const getUser = async id => {
const user = await prisma.user.findUnique({
where: { id }
})
return user
}
// CREATE
export const createUser = async (email, name, birthYear) => {
const user = await prisma.user.create({
data: {
email,
name,
birthYear
}
})
return user
}
// UPDATE
export const updateUser = async (id, updateData) => {
const user = await prisma.user.update({
where: {
id
},
data: {
...updateData
}
})
return user
}
// DELETE
export const deleteUser = async id => {
const user = await prisma.user.delete({
where: {
id
}
})
return user
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment