Skip to content
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
44 changes: 18 additions & 26 deletions orm/express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,15 @@ We found an existing schema.prisma file in your current project directory.

Connect Prisma ORM to your Prisma Postgres database with this URL:

prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
postgresql://user:password@host:port/database

--- Next steps ---

Go to https://pris.ly/ppg-init for detailed instructions.

1. Install and use the Prisma Accelerate extension
Prisma Postgres requires the Prisma Accelerate extension for querying. If you haven't already installed it, install it in your project:
npm install @prisma/extension-accelerate

...and add it to your Prisma Client instance:
import { withAccelerate } from "@prisma/extension-accelerate"

const prisma = new PrismaClient().$extends(withAccelerate())
1. Install the PostgreSQL adapter
This example uses the PostgreSQL driver adapter. If you haven't already installed it, install it in your project:
npm install @prisma/adapter-pg

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

```bash
# .env
DATABASE_URL=prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
DATABASE_URL=postgresql://user:password@host:port/database
```

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):
Expand All @@ -121,6 +116,18 @@ Run the following command to create tables in your database. This creates the `U
npx prisma migrate dev --name init
```

### 2.1. Configure Prisma Client with the adapter

This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`src/index.ts`](./src/index.ts):

```ts
import { PrismaClient } from '../prisma/generated/client'
import { PrismaPg } from '@prisma/adapter-pg'

const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
const prisma = new PrismaClient({ adapter: pool })
```

Execute the seed file in [`prisma/seed.ts`](./prisma/seed.ts) to populate your database with some sample data, by running:

```terminal
Expand Down Expand Up @@ -410,24 +417,9 @@ Learn more about the different connection configurations in the [docs](https://w

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

### Remove the Prisma Client extension

Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres:

```terminal
npm uninstall @prisma/extension-accelerate
```

Remove the client extension from your `PrismaClient` instance:

```diff
- const prisma = new PrismaClient().$extends(withAccelerate())
+ const prisma = new PrismaClient()
```

### Your own PostgreSQL database

To use your own PostgreSQL database remove the `@prisma/extension-accelerate` package and remove the Prisma Client extension.
This example already uses a standard PostgreSQL connection with the `@prisma/adapter-pg` adapter. You can connect to any PostgreSQL database using a standard connection string.

### SQLite

Expand Down
16 changes: 7 additions & 9 deletions orm/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
"version": "1.0.0",
"license": "MIT",
"scripts": {
"dev": "ts-node src/index.ts"
"dev": "tsx src/index.ts"
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/extension-accelerate": "2.0.2",
"@prisma/adapter-pg": "6.18.0",
"@prisma/client": "6.18.0",
"express": "5.1.0"
},
"devDependencies": {
"@types/express": "5.0.5",
"@types/node": "22.18.12",
"prisma": "6.9.0",
"ts-node": "10.9.2",
"dotenv": "^17.2.1",
"prisma": "6.18.0",
"tsx": "^4.20.6",
"typescript": "5.8.2"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
}
}
15 changes: 15 additions & 0 deletions orm/express/prisma.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig, env } from 'prisma/config'
import 'dotenv/config'

export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
seed: 'tsx prisma/seed.ts',
},
engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
})

4 changes: 3 additions & 1 deletion orm/express/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand Down
12 changes: 9 additions & 3 deletions orm/express/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PrismaClient, Prisma } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'
import { PrismaClient, Prisma } from './generated/client'
import { PrismaPg } from '@prisma/adapter-pg'

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

const userData: Prisma.UserCreateInput[] = [
{
Expand Down Expand Up @@ -51,6 +52,11 @@ const userData: Prisma.UserCreateInput[] = [

async function main() {
console.log(`Start seeding ...`)

// Clear existing data
await prisma.post.deleteMany()
await prisma.user.deleteMany()

for (const u of userData) {
const user = await prisma.user.create({
data: u,
Expand Down
18 changes: 10 additions & 8 deletions orm/express/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Prisma, PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'
import 'dotenv/config'
import { Prisma, PrismaClient } from '../prisma/generated/client'
import { PrismaPg } from '@prisma/adapter-pg'
import express from 'express'

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

const app = express()

Expand Down Expand Up @@ -121,11 +123,11 @@ app.get('/feed', async (req, res) => {

const or: Prisma.PostWhereInput = searchString
? {
OR: [
{ title: { contains: searchString as string } },
{ content: { contains: searchString as string } },
],
}
OR: [
{ title: { contains: searchString as string } },
{ content: { contains: searchString as string } },
],
}
: {}

const posts = await prisma.post.findMany({
Expand Down
11 changes: 8 additions & 3 deletions orm/express/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"sourceMap": true,
"outDir": "dist",
"strict": true,
"lib": ["esnext"],
"esModuleInterop": true
"lib": [
"esnext"
],
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true
}
}
}
44 changes: 18 additions & 26 deletions orm/fastify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,15 @@ We found an existing schema.prisma file in your current project directory.

Connect Prisma ORM to your Prisma Postgres database with this URL:

prisma+postgres://accelerate.prisma-data.net/?api_key=...
postgresql://user:password@host:port/database

--- Next steps ---

Go to https://pris.ly/ppg-init for detailed instructions.

1. Install and use the Prisma Accelerate extension
Prisma Postgres requires the Prisma Accelerate extension for querying. If you haven't already installed it, install it in your project:
npm install @prisma/extension-accelerate

...and add it to your Prisma Client instance:
import { withAccelerate } from "@prisma/extension-accelerate"

const prisma = new PrismaClient().$extends(withAccelerate())
1. Install the PostgreSQL adapter
This example uses the PostgreSQL driver adapter. If you haven't already installed it, install it in your project:
npm install @prisma/adapter-pg

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

```bash
# .env
DATABASE_URL=prisma+postgres://accelerate.prisma-data.net/?api_key=ey...
DATABASE_URL=postgresql://user:password@host:port/database
```

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):
Expand All @@ -121,6 +116,18 @@ Run the following command to create tables in your database. This creates the `U
npx prisma migrate dev --name init
```

### 2.1. Configure Prisma Client with the adapter

This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`src/index.ts`](./src/index.ts):

```ts
import { PrismaClient } from '../prisma/generated/client'
import { PrismaPg } from '@prisma/adapter-pg'

const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
const prisma = new PrismaClient({ adapter: pool })
```

Execute the seed file in [`prisma/seed.ts`](./prisma/seed.ts) to populate your database with some sample data, by running:

```terminal
Expand Down Expand Up @@ -409,24 +416,9 @@ Learn more about the different connection configurations in the [docs](https://w

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

### Remove the Prisma Client extension

Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres:

```terminal
npm uninstall @prisma/extension-accelerate
```

Remove the client extension from your `PrismaClient` instance:

```diff
- const prisma = new PrismaClient().$extends(withAccelerate())
+ const prisma = new PrismaClient()
```

### Your own PostgreSQL database

To use your own PostgreSQL database remove the `@prisma/extension-accelerate` package and remove the Prisma client extension.
This example already uses a standard PostgreSQL connection with the `@prisma/adapter-pg` adapter. You can connect to any PostgreSQL database using a standard connection string.

### SQLite

Expand Down
16 changes: 7 additions & 9 deletions orm/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
"version": "1.0.0",
"license": "MIT",
"scripts": {
"dev": "ts-node src/index.ts"
"dev": "tsx src/index.ts"
},
"dependencies": {
"@prisma/client": "6.9.0",
"@prisma/client": "6.18.0",
"fastify": "5.6.1",
"@prisma/extension-accelerate": "2.0.2"
"@prisma/adapter-pg": "6.18.0"
},
"devDependencies": {
"@types/node": "22.18.12",
"prisma": "6.9.0",
"ts-node": "10.9.2",
"dotenv": "^17.2.1",
"prisma": "6.18.0",
"tsx": "^4.20.6",
"typescript": "5.8.2"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
}
}
}
15 changes: 15 additions & 0 deletions orm/fastify/prisma.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig, env } from 'prisma/config'
import 'dotenv/config'

export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
seed: 'tsx prisma/seed.ts',
},
engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
})

4 changes: 3 additions & 1 deletion orm/fastify/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "./generated"
engineType = "client"
}

datasource db {
Expand Down
12 changes: 9 additions & 3 deletions orm/fastify/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PrismaClient, Prisma } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'
import { PrismaClient, Prisma } from './generated/client'
import { PrismaPg } from '@prisma/adapter-pg'

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

const userData: Prisma.UserCreateInput[] = [
{
Expand Down Expand Up @@ -51,6 +52,11 @@ const userData: Prisma.UserCreateInput[] = [

async function main() {
console.log(`Start seeding ...`)

// Clear existing data
await prisma.post.deleteMany()
await prisma.user.deleteMany()

for (const u of userData) {
const user = await prisma.user.create({
data: u,
Expand Down
18 changes: 10 additions & 8 deletions orm/fastify/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Prisma, PrismaClient } from '@prisma/client'
import { withAccelerate } from '@prisma/extension-accelerate'
import 'dotenv/config'
import { Prisma, PrismaClient } from '../prisma/generated/client'
import { PrismaPg } from '@prisma/adapter-pg'

import fastify from 'fastify'

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

const app = fastify({ logger: true })

Expand Down Expand Up @@ -133,11 +135,11 @@ app.get<{

const or: Prisma.PostWhereInput = searchString
? {
OR: [
{ title: { contains: searchString as string } },
{ content: { contains: searchString as string } },
],
}
OR: [
{ title: { contains: searchString as string } },
{ content: { contains: searchString as string } },
],
}
: {}

const posts = await prisma.post.findMany({
Expand Down
Loading
Loading