Skip to content

Commit

Permalink
Use @prisma/neon-adapter with @vercel/postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
adriancooney committed Oct 10, 2023
1 parent a1d0e3a commit 9e8c9e5
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 58 deletions.
1 change: 1 addition & 0 deletions storage/postgres-prisma/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers=true
11 changes: 10 additions & 1 deletion storage/postgres-prisma/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { PrismaClient } from '@prisma/client'
import { PrismaNeon } from '@prisma/adapter-neon'
import { createPool } from '@vercel/postgres'

declare global {
var prisma: PrismaClient | undefined
}

const prisma = global.prisma || new PrismaClient()
// Caveats:
// 1. "@prisma/adapter-neon" warns of missing peer dependency "@neondatabase/serverless".
// 2. Trying to build with pnpm and without `autoInstallPeers` fails without the `@neondatabase/serverless` peer dependency.
// 3. Adapter is called "PrismaNeon" which might be confusing. "PrismaVercelPostgres" would be preferred.

const pool = createPool()
const adapter = new PrismaNeon(pool);
const prisma = global.prisma || new PrismaClient({ adapter })

if (process.env.NODE_ENV === 'development') global.prisma = prisma

Expand Down
6 changes: 4 additions & 2 deletions storage/postgres-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
},
"dependencies": {
"@prisma/client": "^5.4.1",
"@prisma/adapter-neon": "^5.4.2",
"@prisma/client": "^5.4.2",
"@types/ms": "^0.7.32",
"@types/node": "20.8.3",
"@types/react": "18.2.25",
"@types/react-dom": "18.2.11",
"@vercel/postgres": "^0.5.0",
"autoprefixer": "10.4.16",
"eslint": "8.51.0",
"eslint-config-next": "13.5.4",
"ms": "^2.1.3",
"next": "13.5.4",
"postcss": "8.4.31",
"prisma": "^5.4.1",
"prisma": "^5.4.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.3",
Expand Down
Loading

0 comments on commit 9e8c9e5

Please sign in to comment.