Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

341 feat replace prisma neon with turso #355

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const CourseLayout = async ({
},
},
},
cacheStrategy: {
ttl: 15,
swr: 30,
},
});

if (!course) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ const CourseIdPage = async ({ params }: { params: { courseId: string } }) => {
},
},
},
cacheStrategy: {
ttl: 15,
swr: 30,
},
});

const userProgress = await db.userProgress.findFirst({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const SearchPage = async ({ searchParams }: SearchPageProps) => {
orderBy: {
name: 'asc',
},
cacheStrategy: {
ttl: 600,
swr: 1200,
},
});

const isPaidMember = await checkSubscription();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { Button } from '@ui/index';

import { db } from '@/app/lib/db';
import { getCurrentUser } from '@/app/lib/session';
Expand Down Expand Up @@ -58,14 +59,13 @@ const ChapterIdPage = async ({
<div className="p-6">
<div className="flex items-center justify-between">
<div className="w-full">
<Link
href={`/learn/teacher/courses/${params.courseId}`}
className="mb-6 flex items-center text-sm transition hover:opacity-75"
>
<Icons.arrowLeft className="mr-2 h-4 w-4 text-brand" />
Back to playbook setup
<Link href={`/learn/teacher/courses/${params.courseId}`}>
<Button variant="outline" className="mb-6">
<Icons.arrowLeft className="mr-2 h-4 w-4 text-brand" />
Back to playbook setup
</Button>
</Link>
<div className="flex w-full items-center justify-between">
<div className="mt-6 flex w-full items-center justify-between">
<div className="flex flex-col gap-y-2">
<h1 className="font-display tracking-tight text-2xl">
Create a play
Expand Down
6 changes: 3 additions & 3 deletions apps/lms/app/config/navbar-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { Button } from '@ui/components/ui/button';
import { ExitIcon, ModeToggle } from '@ui/index';
import { ModeToggle } from '@ui/index';

import { isTeacher } from '@/app/lib/teacher';
import { SearchInput } from '@/app/ui/search-input';
Expand All @@ -28,8 +28,8 @@ export const NavbarRoutes = ({ userId }) => {
{isTeacherPage || isCoursePage ? (
<Link href="/learn">
<Button size="sm" variant="outline">
<ExitIcon className="mr-2 h-4 w-4" />
Exit
<Icons.signOut className="mr-2 h-4 w-4" />
{isTeacherPage ? 'Exit teacher mode' : 'Exit playbook'}
</Button>
</Link>
) : isTeacher(userId) ? (
Expand Down
4 changes: 0 additions & 4 deletions apps/lms/app/lib/actions/get-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export const getAnalytics = async () => {
include: {
course: true,
},
cacheStrategy: {
ttl: 30,
swr: 60,
},
});

const groupedEarnings = groupByCourse(purchases);
Expand Down
24 changes: 0 additions & 24 deletions apps/lms/app/lib/actions/get-chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@ export const getChapter = async ({
isPublished: true,
id: courseId,
},
cacheStrategy: {
ttl: 300,
swr: 600,
},
});

const chapter = await db.chapter.findUnique({
where: {
id: chapterId,
isPublished: true,
},
cacheStrategy: {
ttl: 300,
swr: 600,
},
});

if (!chapter || !course) {
Expand All @@ -61,10 +53,6 @@ export const getChapter = async ({
where: {
courseId: courseId,
},
cacheStrategy: {
ttl: 900,
swr: 1800,
},
});
}

Expand All @@ -73,10 +61,6 @@ export const getChapter = async ({
where: {
chapterId: chapterId,
},
cacheStrategy: {
ttl: 900,
swr: 1800,
},
});

nextChapter = await db.chapter.findFirst({
Expand All @@ -90,10 +74,6 @@ export const getChapter = async ({
orderBy: {
position: 'asc',
},
cacheStrategy: {
ttl: 900,
swr: 1800,
},
});
}

Expand All @@ -104,10 +84,6 @@ export const getChapter = async ({
chapterId,
},
},
cacheStrategy: {
ttl: 3,
swr: 6,
},
});

return {
Expand Down
5 changes: 0 additions & 5 deletions apps/lms/app/lib/actions/get-courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const getCourses = async ({
isPublished: true,
title: {
contains: title,
mode: 'insensitive',
},
categoryId,
},
Expand All @@ -54,10 +53,6 @@ export const getCourses = async ({
orderBy: {
createdAt: 'desc',
},
cacheStrategy: {
ttl: 3,
swr: 6,
},
});

const isPaidMember = await checkSubscription();
Expand Down
4 changes: 0 additions & 4 deletions apps/lms/app/lib/actions/get-dashboard-courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ export const getDashboardCourses = async (
},
purchases: true,
},
cacheStrategy: {
ttl: 3,
swr: 6,
},
});

const coursesWithProgress = await Promise.all(
Expand Down
26 changes: 16 additions & 10 deletions apps/lms/app/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { withAccelerate } from '@prisma/extension-accelerate';
import { createClient } from '@libsql/client';
import { PrismaLibSQL } from '@prisma/adapter-libsql';

import { PrismaClient } from '.prisma/client';

const prismaClientSingleton = () => {
return new PrismaClient().$extends(withAccelerate());
};
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
// Instantiate libSQL
const libsql = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
// Instantiate the libSQL driver adapter
const adapter = new PrismaLibSQL(libsql);

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
// Pass the adapter option to the Prisma Client instance
const prisma = globalThis.prisma || new PrismaClient({ adapter });

export const db = prisma;

if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db;
if (process.env.NODE_ENV !== 'production') globalThis.prisma = db;
23 changes: 17 additions & 6 deletions apps/lms/app/ui/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ export const Icons = createIcons({
viewBox="0 0 256 256"
{...props}
>
<path
d="M216,48V208a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V48a8,8,0,0,1,8-8H208A8,8,0,0,1,216,48Z"
opacity="0.2"
/>
<path d="M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208ZM82.34,133.66a8,8,0,0,1,0-11.32l32-32a8,8,0,0,1,11.32,11.32L107.31,120H168a8,8,0,0,1,0,16H107.31l18.35,18.34a8,8,0,0,1-11.32,11.32Z" />
<path d="M112,56V200L40,128Z" opacity="0.2" />
<path d="M216,120H120V56a8,8,0,0,0-13.66-5.66l-72,72a8,8,0,0,0,0,11.32l72,72A8,8,0,0,0,120,200V136h96a8,8,0,0,0,0-16ZM104,180.69,51.31,128,104,75.31Z" />
</svg>
),
arrowRight: (props: IconProps) => (
// Phosphor arrow-square-left
// Phosphor arrow-left
<svg
role="img"
width="24"
Expand Down Expand Up @@ -704,6 +701,20 @@ export const Icons = createIcons({
<path d="M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Zm88-29.84q.06-2.16,0-4.32l14.92-18.64a8,8,0,0,0,1.48-7.06,107.6,107.6,0,0,0-10.88-26.25,8,8,0,0,0-6-3.93l-23.72-2.64q-1.48-1.56-3-3L186,40.54a8,8,0,0,0-3.94-6,107.29,107.29,0,0,0-26.25-10.86,8,8,0,0,0-7.06,1.48L130.16,40Q128,40,125.84,40L107.2,25.11a8,8,0,0,0-7.06-1.48A107.6,107.6,0,0,0,73.89,34.51a8,8,0,0,0-3.93,6L67.32,64.27q-1.56,1.49-3,3L40.54,70a8,8,0,0,0-6,3.94,107.71,107.71,0,0,0-10.87,26.25,8,8,0,0,0,1.49,7.06L40,125.84Q40,128,40,130.16L25.11,148.8a8,8,0,0,0-1.48,7.06,107.6,107.6,0,0,0,10.88,26.25,8,8,0,0,0,6,3.93l23.72,2.64q1.49,1.56,3,3L70,215.46a8,8,0,0,0,3.94,6,107.71,107.71,0,0,0,26.25,10.87,8,8,0,0,0,7.06-1.49L125.84,216q2.16.06,4.32,0l18.64,14.92a8,8,0,0,0,7.06,1.48,107.21,107.21,0,0,0,26.25-10.88,8,8,0,0,0,3.93-6l2.64-23.72q1.56-1.48,3-3L215.46,186a8,8,0,0,0,6-3.94,107.71,107.71,0,0,0,10.87-26.25,8,8,0,0,0-1.49-7.06Zm-16.1-6.5a73.93,73.93,0,0,1,0,8.68,8,8,0,0,0,1.74,5.48l14.19,17.73a91.57,91.57,0,0,1-6.23,15L187,173.11a8,8,0,0,0-5.1,2.64,74.11,74.11,0,0,1-6.14,6.14,8,8,0,0,0-2.64,5.1l-2.51,22.58a91.32,91.32,0,0,1-15,6.23l-17.74-14.19a8,8,0,0,0-5-1.75h-.48a73.93,73.93,0,0,1-8.68,0,8.06,8.06,0,0,0-5.48,1.74L100.45,215.8a91.57,91.57,0,0,1-15-6.23L82.89,187a8,8,0,0,0-2.64-5.1,74.11,74.11,0,0,1-6.14-6.14,8,8,0,0,0-5.1-2.64L46.43,170.6a91.32,91.32,0,0,1-6.23-15l14.19-17.74a8,8,0,0,0,1.74-5.48,73.93,73.93,0,0,1,0-8.68,8,8,0,0,0-1.74-5.48L40.2,100.45a91.57,91.57,0,0,1,6.23-15L69,82.89a8,8,0,0,0,5.1-2.64,74.11,74.11,0,0,1,6.14-6.14A8,8,0,0,0,82.89,69L85.4,46.43a91.32,91.32,0,0,1,15-6.23l17.74,14.19a8,8,0,0,0,5.48,1.74,73.93,73.93,0,0,1,8.68,0,8.06,8.06,0,0,0,5.48-1.74L155.55,40.2a91.57,91.57,0,0,1,15,6.23L173.11,69a8,8,0,0,0,2.64,5.1,74.11,74.11,0,0,1,6.14,6.14,8,8,0,0,0,5.1,2.64l22.58,2.51a91.32,91.32,0,0,1,6.23,15l-14.19,17.74A8,8,0,0,0,199.87,123.66Z" />
</svg>
),
signOut: (props: IconProps) => (
// Phosphor sign-out
<svg
role="img"
width="24"
height="24"
fill="currentColor"
viewBox="0 0 256 256"
{...props}
>
<path d="M216,128l-40,40V88Z" opacity="0.2" />
<path d="M112,216a8,8,0,0,1-8,8H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32h56a8,8,0,0,1,0,16H48V208h56A8,8,0,0,1,112,216Zm109.66-82.34-40,40A8,8,0,0,1,168,168V136H104a8,8,0,0,1,0-16h64V88a8,8,0,0,1,13.66-5.66l40,40A8,8,0,0,1,221.66,133.66Zm-17-5.66L184,107.31v41.38Z" />
</svg>
),
spinner: (props: IconProps) => (
// Phosphor circle-notch
<svg
Expand Down
Loading
Loading