-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove planetscale adapter for prisma
- Loading branch information
1 parent
5508d5d
commit 27e9a98
Showing
6 changed files
with
26 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |