aboutsummaryrefslogtreecommitdiff
path: root/prisma
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-07-25 18:43:13 +0700
committerFactiven <[email protected]>2023-07-25 18:43:13 +0700
commit95393d7c8ba5cf6cd17f2038fc421c0d6d06f2e6 (patch)
tree97154270ec3ad400e63a683e194ea56eca0b9b0b /prisma
parentadded .env disqus shortname (diff)
downloadmoopa-v.3.6.7-beta-v1.4.tar.xz
moopa-v.3.6.7-beta-v1.4.zip
Update_v3.6.7-beta-v1.4v.3.6.7-beta-v1.4
>Implementing database
Diffstat (limited to 'prisma')
-rw-r--r--prisma/schema.prisma34
-rw-r--r--prisma/user.js37
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;
+};