Created
January 8, 2022 09:04
-
-
Save skolhustick/ee6c64f8b32caa2d6adf0c41517fea03 to your computer and use it in GitHub Desktop.
next-js-prisma-orm-mongodb-prisma:user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /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