Skip to content

Commit 04b85a5

Browse files
add prisma.config.ts and pg adapter
1 parent 37abebc commit 04b85a5

25 files changed

Lines changed: 155 additions & 81 deletions

File tree

orm/betterauth-nextjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
},
1010
"dependencies": {
1111
"@prisma/client": "^6.18.0",
12-
"@prisma/extension-accelerate": "^2.0.2",
12+
"@prisma/adapter-pg": "^6.18.0",
1313
"better-auth": "1.3.24",
1414
"next": "15.5.4",
1515
"react": "19.1.0",
1616
"react-dom": "19.1.0"
1717
},
1818
"devDependencies": {
1919
"@eslint/eslintrc": "3.3.1",
20+
"dotenv": "^17.2.1",
2021
"@tailwindcss/postcss": "4.1.14",
2122
"@types/node": "24.6.2",
2223
"@types/react": "19.1.0",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig, env } from 'prisma/config'
2+
import 'dotenv/config'
3+
4+
export default defineConfig({
5+
schema: 'prisma/schema.prisma',
6+
migrations: {
7+
path: 'prisma/migrations',
8+
},
9+
engine: 'classic',
10+
datasource: {
11+
url: env('DATABASE_URL'),
12+
},
13+
})
14+
15+

orm/betterauth-nextjs/prisma/schema.prisma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// learn more about it in the docs: https://pris.ly/d/prisma-schema
33

44
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5-
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
65

76
generator client {
87
provider = "prisma-client"

orm/betterauth-nextjs/src/lib/prisma.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { PrismaPg } from '@prisma/adapter-pg'
12
import { PrismaClient } from '@/generated/prisma/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
const globalForPrisma = global as unknown as { prisma: typeof prisma }
78

orm/nextjs/README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,21 @@ We found an existing schema.prisma file in your current project directory.
6565
6666
--- Database URL ---
6767
68-
Connect Prisma ORM to your Prisma Postgres database with this URL:
69-
70-
prisma+postgres://accelerate.prisma-data.net/?api_key=...
68+
Connect Prisma ORM to your Prisma Postgres database with the provided URL and add it to your `.env` as `DATABASE_URL`.
7169
7270
--- Next steps ---
7371
7472
Go to https://pris.ly/ppg-init for detailed instructions.
7573
76-
1. Install and use the Prisma Accelerate extension
77-
Prisma Postgres requires the Prisma Accelerate extension for querying. If you haven't already installed it, install it in your project:
78-
npm install @prisma/extension-accelerate
79-
80-
...and add it to your Prisma Client instance:
81-
import { withAccelerate } from "@prisma/extension-accelerate"
82-
83-
const prisma = new PrismaClient().$extends(withAccelerate())
74+
1. Install the `@prisma/adapter-pg` driver adapter and configure your Prisma Client instance
75+
```bash
76+
npm install @prisma/adapter-pg
77+
```
78+
```ts
79+
import { PrismaPg } from '@prisma/adapter-pg'
80+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
81+
const prisma = new PrismaClient({ adapter: pool })
82+
```
8483

8584
2. Apply migrations
8685
Run the following command to create and apply a migration:
@@ -112,7 +111,7 @@ Now, paste the URL into it as a value for the `DATABASE_URL` environment variabl
112111

113112
```bash
114113
# .env
115-
DATABASE_URL=prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
114+
DATABASE_URL=postgres://<username>:<password>@<host>:<port>/<database>
116115
```
117116

118117
Run the following command to create tables in your database. This creates the `User` and `Post` tables that are defined in [`prisma/schema.prisma`](./prisma/schema.prisma):
@@ -204,24 +203,9 @@ Learn more about the different connection configurations in the [docs](https://w
204203

205204
<details><summary>Expand for an overview of example configurations with different databases</summary>
206205

207-
### Remove the Prisma Client extension
208-
209-
Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres:
210-
211-
```terminal
212-
npm uninstall @prisma/extension-accelerate
213-
```
214-
215-
Remove the client extension from your `PrismaClient` instance:
216-
217-
```diff
218-
- const prisma = new PrismaClient().$extends(withAccelerate())
219-
+ const prisma = new PrismaClient()
220-
```
221-
222206
### Your own PostgreSQL database
223207

224-
To use your own PostgreSQL database remove the `@prisma/extension-accelerate` package and remove the Prisma client extension.
208+
To use your own PostgreSQL database, set `DATABASE_URL` to your connection string (e.g. `postgres://<username>:<password>@<host>:<port>/<database>`). Ensure your app initializes `PrismaClient` with the `@prisma/adapter-pg` driver adapter as shown above.
225209

226210
### SQLite
227211

orm/nextjs/lib/prisma.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { PrismaPg } from '@prisma/adapter-pg'
12
import { PrismaClient } from '../app/generated/prisma/client'
2-
import { withAccelerate } from '@prisma/extension-accelerate'
33

4-
const prisma = new PrismaClient().$extends(withAccelerate())
4+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
5+
const prisma = new PrismaClient({ adapter: pool })
56

67
const globalForPrisma = global as unknown as { prisma: typeof prisma }
78

orm/nextjs/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111
},
1212
"dependencies": {
1313
"@prisma/client": "^6.18.0",
14+
"@prisma/adapter-pg": "^6.18.0",
1415
"next": "15.3.5",
1516
"react": "19.1.0",
16-
"react-dom": "19.1.0",
17-
"@prisma/extension-accelerate": "^2.0.2"
17+
"react-dom": "19.1.0"
1818
},
1919
"devDependencies": {
2020
"@eslint/eslintrc": "3.3.1",
2121
"@types/node": "22.18.12",
2222
"@types/react": "19.1.8",
2323
"@types/react-dom": "19.1.6",
24+
"dotenv": "^17.2.1",
2425
"eslint": "9.30.1",
2526
"eslint-config-next": "15.3.5",
2627
"postcss": "8.5.6",
2728
"prisma": "^6.18.0",
2829
"tailwindcss": "3.4.17",
2930
"tsx": "4.20.6",
3031
"typescript": "5.8.2"
31-
},
32-
"prisma": {
33-
"seed": "tsx prisma/seed.ts"
3432
}
3533
}

orm/nextjs/prisma.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig, env } from 'prisma/config'
2+
import 'dotenv/config'
3+
4+
export default defineConfig({
5+
schema: 'prisma/schema.prisma',
6+
migrations: {
7+
path: 'prisma/migrations',
8+
seed: 'tsx ./prisma/seed.ts',
9+
},
10+
engine: 'classic',
11+
datasource: {
12+
url: env('DATABASE_URL'),
13+
},
14+
})
15+
16+

orm/nextjs/prisma/schema.prisma

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// learn more about it in the docs: https://pris.ly/d/prisma-schema
33

44
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5-
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
6-
75

86
generator client {
97
provider = "prisma-client"

orm/nuxt-prisma-module/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The app demonstrates:
4242

4343
```bash
4444
# .env
45-
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
45+
DATABASE_URL="postgres://<username>:<password>@<host>:<port>/<database>"
4646
```
4747

4848
6. Apply database migrations:
@@ -67,14 +67,14 @@ The app demonstrates:
6767

6868
## Prisma Postgres Setup
6969

70-
This example uses Prisma Postgres, which requires the Prisma Accelerate extension. The extension is already included in the project dependencies and configured in [`lib/prisma.ts`](./lib/prisma.ts).
71-
72-
The Prisma Client is extended with the Accelerate extension to enable querying against your Prisma Postgres database:
70+
This example uses Prisma Postgres with the `@prisma/adapter-pg` driver adapter configured in [`lib/prisma.ts`](./lib/prisma.ts):
7371

7472
```typescript
75-
import { withAccelerate } from '@prisma/extension-accelerate'
73+
import { PrismaPg } from '@prisma/adapter-pg'
74+
import { PrismaClient } from '../prisma/generated/prisma/client'
7675

77-
const prisma = new PrismaClient().$extends(withAccelerate())
76+
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
77+
const prisma = new PrismaClient({ adapter: pool })
7878
```
7979

8080
## Resources

0 commit comments

Comments
 (0)