From c703e09d6448d34ad75e307f31bbaf11dc7a736c Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sun, 2 Nov 2025 20:35:24 +0530 Subject: [PATCH 1/2] Update misc examples with prisma.config.ts and adapter --- orm/postgis-express/package.json | 7 ++-- orm/postgis-express/prisma.config.ts | 14 +++++++ orm/prisma-mocking-javascript/package.json | 6 +-- .../prisma.config.ts | 13 ++++++ orm/script/README.md | 41 +++++++++---------- orm/script/package.json | 6 +-- orm/script/prisma.config.ts | 14 +++++++ orm/script/script.ts | 5 ++- orm/script/tsconfig.json | 11 +++-- orm/starter/package.json | 8 ++-- orm/starter/prisma.config.ts | 14 +++++++ orm/starter/src/index.ts | 5 ++- orm/starter/tsconfig.json | 6 ++- orm/testing-express/README.md | 41 +++++++++---------- orm/testing-express/package.json | 10 ++--- orm/testing-express/prisma.config.ts | 15 +++++++ orm/testing-express/prisma/seed.ts | 10 ++++- orm/testing-express/src/app.ts | 5 ++- orm/typedsql/package.json | 11 +++-- orm/typedsql/prisma.config.ts | 15 +++++++ orm/typedsql/prisma/schema.prisma | 1 + orm/typedsql/prisma/seed.ts | 5 ++- orm/typedsql/src/index.ts | 5 ++- 23 files changed, 182 insertions(+), 86 deletions(-) create mode 100644 orm/postgis-express/prisma.config.ts create mode 100644 orm/prisma-mocking-javascript/prisma.config.ts create mode 100644 orm/script/prisma.config.ts create mode 100644 orm/starter/prisma.config.ts create mode 100644 orm/testing-express/prisma.config.ts create mode 100644 orm/typedsql/prisma.config.ts diff --git a/orm/postgis-express/package.json b/orm/postgis-express/package.json index 8a8cfe56ee79..cc5a30e43ad6 100644 --- a/orm/postgis-express/package.json +++ b/orm/postgis-express/package.json @@ -7,9 +7,8 @@ "test": "jest" }, "dependencies": { - "@prisma/adapter-pg": "^6.18.0", - "@prisma/client": "^6.18.0", - "@prisma/extension-accelerate": "^2.0.2", + "@prisma/adapter-pg": "6.18.0", + "@prisma/client": "6.18.0", "dotenv": "^16.4.7", "express": "5.1.0" }, @@ -21,7 +20,7 @@ "@types/supertest": "6.0.3", "jest": "29.7.0", "jest-environment-node": "29.7.0", - "prisma": "^6.18.0", + "prisma": "6.18.0", "randomstring": "1.3.1", "supertest": "7.1.4", "ts-jest": "29.4.5", diff --git a/orm/postgis-express/prisma.config.ts b/orm/postgis-express/prisma.config.ts new file mode 100644 index 000000000000..8104ac5e679b --- /dev/null +++ b/orm/postgis-express/prisma.config.ts @@ -0,0 +1,14 @@ +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + engine: 'classic', + datasource: { + url: env('DB_URL'), + }, +}) + diff --git a/orm/prisma-mocking-javascript/package.json b/orm/prisma-mocking-javascript/package.json index 23ba26b16c2f..dfd3fe3f2b2e 100644 --- a/orm/prisma-mocking-javascript/package.json +++ b/orm/prisma-mocking-javascript/package.json @@ -7,11 +7,11 @@ "dev": "node ./client.js" }, "dependencies": { - "@prisma/adapter-better-sqlite3": "^6.17.1", - "@prisma/client": "^6.17.1" + "@prisma/adapter-better-sqlite3": "6.18.0", + "@prisma/client": "6.18.0" }, "devDependencies": { "jest-mock-extended": "3.0.7", - "prisma": "^6.17.1" + "prisma": "6.18.0" } } \ No newline at end of file diff --git a/orm/prisma-mocking-javascript/prisma.config.ts b/orm/prisma-mocking-javascript/prisma.config.ts new file mode 100644 index 000000000000..866fd7e390c5 --- /dev/null +++ b/orm/prisma-mocking-javascript/prisma.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + engine: 'classic', + datasource: { + url: 'file:./dev.db', + }, +}) + diff --git a/orm/script/README.md b/orm/script/README.md index 19fccac1a78f..d2a88f5351d2 100644 --- a/orm/script/README.md +++ b/orm/script/README.md @@ -65,22 +65,22 @@ We found an existing schema.prisma file in your current project directory. --- Database URL --- -Connect Prisma ORM to your Prisma Postgres database with this URL: +Connect Prisma ORM to your PostgreSQL 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 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 -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 configure it in your Prisma Client instance: +import { PrismaClient } from './prisma/generated/client' +import { PrismaPg } from '@prisma/adapter-pg' -...and add it to your Prisma Client instance: -import { withAccelerate } from "@prisma/extension-accelerate" - -const prisma = new PrismaClient().$extends(withAccelerate()) +const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) +const prisma = new PrismaClient({ adapter: pool }) 2. Apply migrations Run the following command to create and apply a migration: @@ -112,7 +112,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): @@ -232,24 +232,21 @@ Learn more about the different connection configurations in the [docs](https://w
Expand for an overview of example configurations with different databases -### Remove the Prisma Client extension - -Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres: +### 2.1. Configure Prisma Client with the adapter -```terminal -npm uninstall @prisma/extension-accelerate -``` +This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`script.ts`](./script.ts): -Remove the client extension from your `PrismaClient` instance: +```ts +import { PrismaClient } from './prisma/generated/client' +import { PrismaPg } from '@prisma/adapter-pg' -```diff -- const prisma = new PrismaClient().$extends(withAccelerate()) -+ const prisma = new PrismaClient() +const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) +const prisma = new PrismaClient({ adapter: pool }) ``` ### 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 diff --git a/orm/script/package.json b/orm/script/package.json index f7ab3bda3f37..39ca3080db38 100644 --- a/orm/script/package.json +++ b/orm/script/package.json @@ -5,13 +5,13 @@ "dev": "tsx ./script.ts" }, "dependencies": { - "@prisma/client": "^6.18.0", - "@prisma/extension-accelerate": "^2.0.2", + "@prisma/adapter-pg": "6.18.0", + "@prisma/client": "6.18.0", "dotenv": "^16.4.7" }, "devDependencies": { "@types/node": "22.15.32", - "prisma": "^6.18.0", + "prisma": "6.18.0", "tsx": "^4.20.6", "typescript": "5.8.2" } diff --git a/orm/script/prisma.config.ts b/orm/script/prisma.config.ts new file mode 100644 index 000000000000..d34737b53690 --- /dev/null +++ b/orm/script/prisma.config.ts @@ -0,0 +1,14 @@ +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + engine: 'classic', + datasource: { + url: env('DATABASE_URL'), + }, +}) + diff --git a/orm/script/script.ts b/orm/script/script.ts index 60d34ee2e731..646b3db4d0d2 100644 --- a/orm/script/script.ts +++ b/orm/script/script.ts @@ -1,8 +1,9 @@ import 'dotenv/config' import { PrismaClient } from './prisma/generated/client' -import { withAccelerate } from '@prisma/extension-accelerate' +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 }) // A `main` function so that we can use async/await async function main() { diff --git a/orm/script/tsconfig.json b/orm/script/tsconfig.json index 86758c0f7a5d..af1d39ffac0f 100644 --- a/orm/script/tsconfig.json +++ b/orm/script/tsconfig.json @@ -3,7 +3,12 @@ "sourceMap": true, "outDir": "dist", "strict": true, - "lib": ["esnext"], - "esModuleInterop": true + "lib": [ + "esnext" + ], + "esModuleInterop": true, + "module": "ESNext", + "moduleResolution": "node", + "resolveJsonModule": true } -} +} \ No newline at end of file diff --git a/orm/starter/package.json b/orm/starter/package.json index 91bd7921de0b..3af607799f66 100644 --- a/orm/starter/package.json +++ b/orm/starter/package.json @@ -11,13 +11,13 @@ "devDependencies": { "@types/node": "22.18.12", "nodemon": "3.1.10", - "prisma": "^6.17.1", + "prisma": "6.18.0", "tsx": "^4.20.6", "typescript": "5.8.2" }, "dependencies": { - "@prisma/client": "^6.17.1", - "@prisma/extension-accelerate": "^2.0.2", + "@prisma/adapter-pg": "6.18.0", + "@prisma/client": "6.18.0", "dotenv": "^16.4.7" }, "prettier": { @@ -31,4 +31,4 @@ "bracketSpacing": true, "arrowParens": "always" } -} +} \ No newline at end of file diff --git a/orm/starter/prisma.config.ts b/orm/starter/prisma.config.ts new file mode 100644 index 000000000000..d34737b53690 --- /dev/null +++ b/orm/starter/prisma.config.ts @@ -0,0 +1,14 @@ +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + engine: 'classic', + datasource: { + url: env('DATABASE_URL'), + }, +}) + diff --git a/orm/starter/src/index.ts b/orm/starter/src/index.ts index da462f7e2c8c..fedfec07d0b6 100644 --- a/orm/starter/src/index.ts +++ b/orm/starter/src/index.ts @@ -1,8 +1,9 @@ import 'dotenv/config'; import { PrismaClient } from '../prisma/generated/client'; -import { withAccelerate } from '@prisma/extension-accelerate'; +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 }); async function main() { const newUser = await prisma.user.create({ diff --git a/orm/starter/tsconfig.json b/orm/starter/tsconfig.json index 3712af1996a4..0f74903b9a76 100644 --- a/orm/starter/tsconfig.json +++ b/orm/starter/tsconfig.json @@ -1,13 +1,15 @@ { "compilerOptions": { "target": "es6", - "module": "commonjs", + "module": "ESNext", + "moduleResolution": "node", "rootDir": ".", "outDir": "./dist", "strict": true, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, - "skipLibCheck": true + "skipLibCheck": true, + "resolveJsonModule": true }, "include": [ "src" diff --git a/orm/testing-express/README.md b/orm/testing-express/README.md index 785d474a2218..d56a6845c1d9 100644 --- a/orm/testing-express/README.md +++ b/orm/testing-express/README.md @@ -65,22 +65,22 @@ We found an existing schema.prisma file in your current project directory. --- Database URL --- -Connect Prisma ORM to your Prisma Postgres database with this URL: +Connect Prisma ORM to your PostgreSQL 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 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 -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 configure it in your Prisma Client instance: +import { PrismaClient } from '../prisma/generated/client' +import { PrismaPg } from '@prisma/adapter-pg' -...and add it to your Prisma Client instance: -import { withAccelerate } from "@prisma/extension-accelerate" - -const prisma = new PrismaClient().$extends(withAccelerate()) +const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) +const prisma = new PrismaClient({ adapter: pool }) 2. Apply migrations Run the following command to create and apply a migration: @@ -112,7 +112,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): @@ -171,24 +171,21 @@ Learn more about the different connection configurations in the [docs](https://w
Expand for an overview of example configurations with different databases -### Remove the Prisma Client extension - -Before you proceed to use your own database, you should remove the Prisma client extension required for Prisma Postgres: +### 2.1. Configure Prisma Client with the adapter -```terminal -npm uninstall @prisma/extension-accelerate -``` +This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`src/app.ts`](./src/app.ts): -Remove the client extension from your `PrismaClient` instance: +```ts +import { PrismaClient } from '../prisma/generated/client' +import { PrismaPg } from '@prisma/adapter-pg' -```diff -- const prisma = new PrismaClient().$extends(withAccelerate()) -+ const prisma = new PrismaClient() +const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) +const prisma = new PrismaClient({ adapter: pool }) ``` ### 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 diff --git a/orm/testing-express/package.json b/orm/testing-express/package.json index 201b68cc6f30..2aaaf099cce5 100644 --- a/orm/testing-express/package.json +++ b/orm/testing-express/package.json @@ -12,9 +12,8 @@ "singleQuote": true }, "dependencies": { - "@prisma/adapter-pg": "^6.18.0", - "@prisma/client": "^6.18.0", - "@prisma/extension-accelerate": "^2.0.2", + "@prisma/adapter-pg": "6.18.0", + "@prisma/client": "6.18.0", "dotenv": "^16.6.1", "express": "5.1.0", "jest-config": "29.7.0" @@ -27,13 +26,10 @@ "jest": "29.7.0", "jest-environment-node": "29.7.0", "nanoid": "5.1.5", - "prisma": "^6.18.0", + "prisma": "6.18.0", "supertest": "7.1.1", "ts-jest": "29.4.5", "tsx": "^4.20.6", "typescript": "5.8.2" - }, - "prisma": { - "seed": "tsx prisma/seed.ts" } } \ No newline at end of file diff --git a/orm/testing-express/prisma.config.ts b/orm/testing-express/prisma.config.ts new file mode 100644 index 000000000000..5dd26718e280 --- /dev/null +++ b/orm/testing-express/prisma.config.ts @@ -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'), + }, +}) + diff --git a/orm/testing-express/prisma/seed.ts b/orm/testing-express/prisma/seed.ts index d691894bae0a..f824b821a738 100644 --- a/orm/testing-express/prisma/seed.ts +++ b/orm/testing-express/prisma/seed.ts @@ -1,7 +1,9 @@ +import 'dotenv/config' import { PrismaClient, Prisma } from './generated/client' -import { withAccelerate } from '@prisma/extension-accelerate' +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[] = [ { @@ -20,6 +22,10 @@ const userData: Prisma.UserCreateInput[] = [ async function main() { console.log(`Start seeding ...`) + + // Clear existing data + await prisma.user.deleteMany() + for (const u of userData) { const user = await prisma.user.create({ data: u, diff --git a/orm/testing-express/src/app.ts b/orm/testing-express/src/app.ts index d02eba313be8..3292fa3e0b88 100644 --- a/orm/testing-express/src/app.ts +++ b/orm/testing-express/src/app.ts @@ -1,9 +1,10 @@ import 'dotenv/config' import { PrismaClient } from '../prisma/generated/client.js' -import { withAccelerate } from '@prisma/extension-accelerate' +import { PrismaPg } from '@prisma/adapter-pg' import express from 'express' -export const prisma = new PrismaClient().$extends(withAccelerate()) +const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! }) +export const prisma = new PrismaClient({ adapter: pool }) export const app = express() app.use(express.json()) diff --git a/orm/typedsql/package.json b/orm/typedsql/package.json index df03ead38114..72f8f4e7e8b8 100644 --- a/orm/typedsql/package.json +++ b/orm/typedsql/package.json @@ -3,9 +3,6 @@ "name": "basic-typedsql", "description": "A simple TypedSQL example", "main": "src/index.ts", - "prisma": { - "seed": "tsx prisma/seed.ts" - }, "scripts": { "start": "tsx src/index.ts", "dev": "tsx src/index.ts --watch", @@ -16,11 +13,13 @@ "author": "", "license": "ISC", "dependencies": { - "@prisma/client": "^6.18.0" + "@prisma/adapter-better-sqlite3": "6.18.0", + "@prisma/client": "6.18.0", + "dotenv": "^16.4.7" }, "devDependencies": { "@types/node": "22.15.32", - "prisma": "^6.18.0", + "prisma": "6.18.0", "tsx": "^4.20.6" } -} +} \ No newline at end of file diff --git a/orm/typedsql/prisma.config.ts b/orm/typedsql/prisma.config.ts new file mode 100644 index 000000000000..199c491aa576 --- /dev/null +++ b/orm/typedsql/prisma.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } 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: process.env.DATABASE_URL || 'file:./dev.db', + }, +}) + diff --git a/orm/typedsql/prisma/schema.prisma b/orm/typedsql/prisma/schema.prisma index 9c18c8995bbd..60c00decd29a 100644 --- a/orm/typedsql/prisma/schema.prisma +++ b/orm/typedsql/prisma/schema.prisma @@ -1,6 +1,7 @@ generator client { provider = "prisma-client" output = "./generated" + engineType = "client" previewFeatures = ["typedSql"] } diff --git a/orm/typedsql/prisma/seed.ts b/orm/typedsql/prisma/seed.ts index df62b63169f1..8f700b62a066 100644 --- a/orm/typedsql/prisma/seed.ts +++ b/orm/typedsql/prisma/seed.ts @@ -1,4 +1,6 @@ +import 'dotenv/config' import { PrismaClient, Prisma, User } from '../prisma/generated/client' +import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' const NUM_USERS = 1000 const COUNT_BLUE = 300 @@ -16,7 +18,8 @@ enum EventType { CheckedOut = 'CheckedOut', } -const prisma = new PrismaClient() +const adapter = new PrismaBetterSQLite3({ url: process.env.DATABASE_URL || 'file:./dev.db' }) +const prisma = new PrismaClient({ adapter }) async function main() { const usersInput: Prisma.UserCreateInput[] = [] diff --git a/orm/typedsql/src/index.ts b/orm/typedsql/src/index.ts index 9ed35c87f83d..858ab8ed0efb 100644 --- a/orm/typedsql/src/index.ts +++ b/orm/typedsql/src/index.ts @@ -1,10 +1,13 @@ +import 'dotenv/config' import { PrismaClient } from '../prisma/generated/client' +import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' import { conversionByVariant } from '../prisma/generated/sql' import { filterTrackingEvents } from '../prisma/generated/sql' import { getTrackingEvents } from '../prisma/generated/sql' async function main() { - const prisma = new PrismaClient() + const adapter = new PrismaBetterSQLite3({ url: process.env.DATABASE_URL || 'file:./dev.db' }) + const prisma = new PrismaClient({ adapter }) const stats = await prisma.$queryRawTyped(conversionByVariant()) console.log(stats) From 9d8a0bcbbc511db2aca31f54ae17c0e6887b8eed Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sun, 2 Nov 2025 22:26:43 +0530 Subject: [PATCH 2/2] update readme --- orm/script/README.md | 31 ++++--------------------------- orm/starter/README.md | 4 +--- orm/testing-express/README.md | 31 ++++--------------------------- orm/typedsql/README.md | 6 +++--- 4 files changed, 12 insertions(+), 60 deletions(-) diff --git a/orm/script/README.md b/orm/script/README.md index d2a88f5351d2..3f1146b71c65 100644 --- a/orm/script/README.md +++ b/orm/script/README.md @@ -71,32 +71,21 @@ postgresql://user:password@host:port/database --- Next steps --- -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 - -...and configure it in your Prisma Client instance: -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 }) - -2. Apply migrations +1. Apply migrations Run the following command to create and apply a migration: npx prisma migrate dev -3. Manage your data +2. Manage your data View and edit your data locally by running this command: npx prisma studio ...or online in Console: https://console.prisma.io/{workspaceId}/{projectId}/studio -4. Send queries from your app +3. Send queries from your app If you already have an existing app with Prisma ORM, you can now run it and it will send queries against your newly created Prisma Postgres instance. -5. Learn more +4. Learn more For more info, visit the Prisma Postgres docs: https://pris.ly/ppg-docs ``` @@ -232,18 +221,6 @@ Learn more about the different connection configurations in the [docs](https://w
Expand for an overview of example configurations with different databases -### 2.1. Configure Prisma Client with the adapter - -This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`script.ts`](./script.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 }) -``` - ### Your own PostgreSQL database 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. diff --git a/orm/starter/README.md b/orm/starter/README.md index f6c4533e0022..aa2e085fef8d 100644 --- a/orm/starter/README.md +++ b/orm/starter/README.md @@ -53,11 +53,9 @@ Now, open the `.env` file and update the `DATABASE_URL` environment variables wi ```bash # .env -DATABASE_URL="__YOUR_DATABASE_CONNECTION_STRING__" +DATABASE_URL="postgresql://user:password@host:port/database" ``` -Note that `__YOUR_DATABASE_CONNECTION_STRING__` is a placeholder value that you need to replace with the values of your connection string. - ### 3. Run a database migration to create the `User` table The Prisma schema file contains a single `User` model. You can map this model to the database and create the corresponding `User` table using the following command: diff --git a/orm/testing-express/README.md b/orm/testing-express/README.md index d56a6845c1d9..c9464d2c4920 100644 --- a/orm/testing-express/README.md +++ b/orm/testing-express/README.md @@ -71,32 +71,21 @@ postgresql://user:password@host:port/database --- Next steps --- -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 - -...and configure it in your Prisma Client instance: -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 }) - -2. Apply migrations +1. Apply migrations Run the following command to create and apply a migration: npx prisma migrate dev -3. Manage your data +2. Manage your data View and edit your data locally by running this command: npx prisma studio ...or online in Console: https://console.prisma.io/{workspaceId}/{projectId}/studio -4. Send queries from your app +3. Send queries from your app If you already have an existing app with Prisma ORM, you can now run it and it will send queries against your newly created Prisma Postgres instance. -5. Learn more +4. Learn more For more info, visit the Prisma Postgres docs: https://pris.ly/ppg-docs ``` @@ -171,18 +160,6 @@ Learn more about the different connection configurations in the [docs](https://w
Expand for an overview of example configurations with different databases -### 2.1. Configure Prisma Client with the adapter - -This example uses the PostgreSQL driver adapter. The Prisma Client is configured in [`src/app.ts`](./src/app.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 }) -``` - ### Your own PostgreSQL database 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. diff --git a/orm/typedsql/README.md b/orm/typedsql/README.md index 4527f93d761c..59edd467b8ce 100644 --- a/orm/typedsql/README.md +++ b/orm/typedsql/README.md @@ -37,7 +37,7 @@ npm install ### 2. Create and seed the database -Run the following command to create your SQLite database file. This also creates the `User` and `Post` tables that are defined in [`prisma/schema.prisma`](./prisma/schema.prisma): +Run the following command to create your SQLite database file. This also creates the `User` and `TrackingEvent` tables that are defined in [`prisma/schema.prisma`](./prisma/schema.prisma): ``` npx prisma migrate dev --name init @@ -62,7 +62,7 @@ This command runs `prisma generate --sql`, which will generate the Prisma Client npm run dev ``` -This command will run [`index.ts`](./index.ts), which will execute the SQL query defined in [`prisma/sql/conversionByVariant.sql`](./prisma/sql/conversionByVariant.sql) and print the results to the console. +This command will run [`src/index.ts`](./src/index.ts), which will execute the SQL query defined in [`prisma/sql/conversionByVariant.sql`](./prisma/sql/conversionByVariant.sql) and print the results to the console. ## Project Structure @@ -73,7 +73,7 @@ This example project is structured similarly to the [starter example](https://gi Key areas to look at: 1. Database schema: [`prisma/schema.prisma`](./prisma/schema.prisma) -2. Example SQL query: [`prisma/sql/conversionByVariant.sql`](./prisma/sql/conversionByVariant.sql) +2. Example SQL queries: [`prisma/sql/`](./prisma/sql/) 3. Query execution: [`src/index.ts`](./src/index.ts) 4. Data seeding: [`prisma/seed.ts`](./prisma/seed.ts) 5. Build and run scripts: [`package.json`](./package.json)