diff options
Diffstat (limited to 'prisma')
| -rw-r--r-- | prisma/schema.prisma | 34 | ||||
| -rw-r--r-- | prisma/user.js | 37 |
2 files changed, 71 insertions, 0 deletions
diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..adf0fa1 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,34 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model WatchListEpisode { + id String @id @default(cuid()) + title String + episode Int + url String + timeWatched Int + duration Int + watchListItem WatchListItem @relation(fields: [watchListItemId], references: [id]) + watchListItemId String +} + +model WatchListItem { + id String @id @default(cuid()) + title String + episodes WatchListEpisode[] + userProfile UserProfile? @relation(fields: [userProfileId], references: [id]) + userProfileId String? +} + +model UserProfile { + id String @id @default(cuid()) + name String + setting Json + watchList WatchListItem[] +} diff --git a/prisma/user.js b/prisma/user.js new file mode 100644 index 0000000..d58c1a9 --- /dev/null +++ b/prisma/user.js @@ -0,0 +1,37 @@ +import { PrismaClient } from "@prisma/client"; +const prisma = new PrismaClient(); + +export const createUser = async (name, setting, animeWatched) => { + const user = await prisma.user.create({ + data: { + name, + setting, + animeWatched, + }, + }); + + return user; +}; + +export const updateUser = async (name, setting, animeWatched) => { + const user = await prisma.user.update({ + where: { + name: name, + }, + data: { + setting, + animeWatched, + }, + }); + + return user; +}; + +export const getUser = async (name) => { + const user = await prisma.user.findUnique({ + where: { + name: name, + }, + }); + return user; +}; |