Skip to content

Commit

Permalink
feat: remove planetscale adapter for prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
albugowy15 committed Mar 8, 2024
1 parent 5508d5d commit 27e9a98
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 40 deletions.
3 changes: 1 addition & 2 deletions src/server/api/routers/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "@/server/api/trpc";
import { prisma } from "@/server/db";
import prisma from "@/server/db";

export interface StatisticData {
id: string;
Expand Down
7 changes: 3 additions & 4 deletions src/server/api/routers/frs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { titleSchema } from "@/app/my-frs/schema";
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
import { TRPCError } from "@trpc/server";
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
import { prisma } from "@/server/db";
import { titleSchema } from "@/app/my-frs/schema";
import prisma from "@/server/db";

const frsPlanSchema = z.object({
title: titleSchema,
Expand Down
3 changes: 1 addition & 2 deletions src/server/api/routers/trade-matkul.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { TRPCError } from "@trpc/server";
import { z } from "zod";

import {
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "@/server/api/trpc";
import { prisma } from "@/server/db";
import prisma from "@/server/db";

export const tradeMatkulRouter = createTRPCRouter({
createTradeMatkul: protectedProcedure
Expand Down
27 changes: 12 additions & 15 deletions src/server/api/routers/user.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { forgotPasswordSchema } from "@/app/lupa-password/schema";
import { editProfileSchema } from "@/app/profil/schema";
import { registerSchema } from "@/app/register/schema";
import { changePasswordSchema } from "@/app/ubah-password/schema";
import { env } from "@/env.mjs";
import { passwordSchema } from "@/lib/schema";
import {
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "@/server/api/trpc";
import prisma from "@/server/db";
import { TRPCError } from "@trpc/server";
import { kv } from "@vercel/kv";
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";
import { Resend } from "resend";
import { z } from "zod";

import {
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "@/server/api/trpc";
import { prisma } from "@/server/db";

import { env } from "@/env.mjs";

import { passwordSchema } from "@/lib/schema";
import { registerSchema } from "@/app/register/schema";
import { editProfileSchema } from "@/app/profil/schema";
import { changePasswordSchema } from "@/app/ubah-password/schema";
import { forgotPasswordSchema } from "@/app/lupa-password/schema";

export const userRouter = createTRPCRouter({
register: publicProcedure
.input(registerSchema)
Expand Down
3 changes: 1 addition & 2 deletions src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {
type NextAuthOptions,
} from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

import { env } from "@/env.mjs";
import bcrypt from "bcryptjs";
import jwt from "jsonwebtoken";
import { prisma } from "./db";
import prisma from "@/server/db";

export interface LoginResponseData {
username: string;
Expand Down
23 changes: 8 additions & 15 deletions src/server/db.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { env } from "@/env.mjs";
import { PrismaClient } from "@prisma/client";
import { Client } from "@planetscale/database";
import { fetch as undiciFetch } from "undici";
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";

const prismaClientSingleton = () => {
const client = new Client({ url: env.DATABASE_URL, fetch: undiciFetch });
const adapter = new PrismaPlanetScale(client);
return new PrismaClient({
log: env.NODE_ENV === "development" ? ["error", "warn"] : ["error"],
adapter,
});
return new PrismaClient();
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
declare global {
// eslint-disable-next-line no-var
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
}

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
const prisma = globalThis.prisma ?? prismaClientSingleton();

export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
export default prisma;

if (env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
if (env.NODE_ENV !== "production") globalThis.prisma = prisma;

0 comments on commit 27e9a98

Please sign in to comment.