Skip to content

Commit 4d035f8

Browse files
committed
fix: table events only. prisma client
1 parent 8c905df commit 4d035f8

File tree

7 files changed

+103
-85
lines changed

7 files changed

+103
-85
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_URL="postgresql://USERNAME:PASSWORD@localhost:6500/DATABASENAME?schema=public"

app/routes/event.$slug.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { LoaderFunctionArgs } from "@remix-run/node";
2+
import { json, useLoaderData } from "@remix-run/react";
3+
4+
import { prisma } from "~/utils/db.server";
5+
6+
export const loader = async ({ params }: LoaderFunctionArgs) => {
7+
if (!params.slug) {
8+
throw new Error("Missing eventid param");
9+
}
10+
const event = await prisma.events.findFirst({
11+
where: {
12+
slug: params.slug,
13+
},
14+
});
15+
if (!event) {
16+
throw new Response("Not Found", { status: 404 });
17+
}
18+
return json({ event });
19+
};
20+
21+
export default function Event() {
22+
const { event } = useLoaderData<typeof loader>();
23+
return (
24+
<div className="w-full max-w-6xl mx-auto">
25+
<h1>{event.title}</h1>
26+
<h2>Deskripsi</h2>
27+
<img src={event.imageUrl} alt={event.title} />
28+
<p>{event.description}</p>
29+
</div>
30+
);
31+
}

app/utils/db.server.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
let prisma: PrismaClient;
4+
5+
declare global {
6+
var __db__: PrismaClient | undefined; // eslint-disable-line no-var
7+
}
8+
9+
/**
10+
* This is needed because in development we don't want to restart
11+
* the server with every change, but we want to make sure we don't
12+
* create a new connection to the DB with every change either.
13+
* In production, we'll have a single connection to the DB.
14+
*/
15+
if (process.env.NODE_ENV === "production") {
16+
prisma = new PrismaClient();
17+
} else {
18+
if (!global.__db__) {
19+
global.__db__ = new PrismaClient();
20+
}
21+
prisma = global.__db__;
22+
prisma.$connect();
23+
}
24+
25+
export { prisma };

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@netlify/functions": "^2.6.0",
1717
"@netlify/remix-adapter": "^2.3.1",
1818
"@fontsource/geist-sans": "^5.0.3",
19+
"@prisma/client": "^5.18.0",
1920
"@radix-ui/react-avatar": "^1.1.0",
2021
"@radix-ui/react-dialog": "^1.1.1",
2122
"@radix-ui/react-slot": "^1.1.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `Event` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropTable
8+
DROP TABLE "Event";
9+
10+
-- CreateTable
11+
CREATE TABLE "Events" (
12+
"id" TEXT NOT NULL,
13+
"slug" TEXT NOT NULL,
14+
"title" TEXT NOT NULL,
15+
"imageUrl" TEXT NOT NULL,
16+
"dateTimeStart" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
17+
"dateTimeEnd" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
18+
"url" TEXT NOT NULL,
19+
"description" TEXT NOT NULL,
20+
"locationName" TEXT NOT NULL,
21+
"locationAddress" TEXT NOT NULL,
22+
"eventAgendas" TEXT[],
23+
"registration" TEXT NOT NULL,
24+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
25+
"updatedAt" TIMESTAMP(3) NOT NULL,
26+
27+
CONSTRAINT "Events_pkey" PRIMARY KEY ("id")
28+
);
29+
30+
-- CreateIndex
31+
CREATE UNIQUE INDEX "Events_slug_key" ON "Events"("slug");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "postgresql"

prisma/schema.prisma

Lines changed: 11 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,21 @@ datasource db {
1111
url = env("DATABASE_URL")
1212
}
1313

14-
model User {
14+
model Events {
1515
id String @id @default(cuid())
1616
17-
email String @unique
18-
username String @unique
19-
phone String? @unique // numeric string
20-
21-
fullname String
22-
nickname String?
23-
24-
profile UserProfile?
25-
userProfileId String @unique
26-
role Role @relation(fields: [roleId], references: [id])
27-
roleId String
28-
29-
createdAt DateTime @default(now())
30-
updatedAt DateTime @updatedAt
31-
32-
@@index([id])
33-
@@index([email])
34-
}
35-
36-
model Role {
37-
id String @id @default(cuid())
38-
39-
sequence Int? @unique // 1, 2, 3, ...
40-
symbol String @unique // ROOT, ADMIN, MEMBER, ...
41-
name String @unique // Root, Admin, Member, ...
42-
description String? @db.Text // Summary of abilities
43-
44-
users User[]
45-
46-
createdAt DateTime @default(now())
47-
updatedAt DateTime @updatedAt
48-
49-
@@index([symbol])
50-
}
51-
52-
model Event {
53-
id String @id @default(cuid())
54-
55-
slug String @unique
56-
title String @db.Text
57-
description String @db.Text
58-
content String? @db.Text // Rich HTML Text
59-
url String? // Url for online or hybrid
60-
61-
dateTimeStart DateTime @default(now())
62-
dateTimeEnd DateTime @default(now())
63-
64-
imageUrl String
65-
17+
slug String @unique
18+
title String @db.Text
19+
imageUrl String
20+
dateTimeStart DateTime @default(now())
21+
dateTimeEnd DateTime @default(now())
22+
url String // Url for online or hybrid
23+
description String @db.Text
6624
locationName String
67-
locationAddress String?
68-
69-
eventAgendas EventAgenda[]
70-
71-
registration String @db.Text
25+
locationAddress String
26+
eventAgendas String[]
27+
registration String @db.Text
7228
7329
createdAt DateTime @default(now())
7430
updatedAt DateTime @updatedAt
7531
}
76-
77-
model EventAgenda {
78-
id String @id @default(cuid())
79-
title String
80-
description String
81-
speaker UserProfile? @relation(fields: [userProfileId], references: [id])
82-
userProfileId String?
83-
Event Event? @relation(fields: [eventId], references: [id])
84-
eventId String?
85-
dateTimeStart DateTime
86-
dateTimeEnd DateTime
87-
}
88-
89-
// used by User & Event (event agenda has speakers)
90-
model UserProfile {
91-
id String @id @default(cuid())
92-
93-
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
94-
userId String @unique
95-
96-
headline String?
97-
avatar String?
98-
99-
createdAt DateTime @default(now())
100-
updatedAt DateTime @updatedAt
101-
eventAgendas EventAgenda[]
102-
103-
@@unique([id, userId])
104-
@@index([userId])
105-
}

0 commit comments

Comments
 (0)