diff --git a/orm/postgis-express/package.json b/orm/postgis-express/package.json index 9aeca2d100e1..45bfb1a867f3 100644 --- a/orm/postgis-express/package.json +++ b/orm/postgis-express/package.json @@ -9,8 +9,7 @@ "dependencies": { "@prisma/adapter-pg": "6.18.0", "@prisma/client": "6.18.0", - "@prisma/extension-accelerate": "2.0.2", - "dotenv": "16.6.1", + "dotenv": "^16.4.7", "express": "5.1.0" }, "devDependencies": { 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/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..3f1146b71c65 100644 --- a/orm/script/README.md +++ b/orm/script/README.md @@ -65,38 +65,27 @@ 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 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()) - -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 ``` @@ -112,7 +101,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 +221,9 @@ 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: - -```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 diff --git a/orm/script/package.json b/orm/script/package.json index 44a562490a9e..39ca3080db38 100644 --- a/orm/script/package.json +++ b/orm/script/package.json @@ -5,14 +5,14 @@ "dev": "tsx ./script.ts" }, "dependencies": { + "@prisma/adapter-pg": "6.18.0", "@prisma/client": "6.18.0", - "@prisma/extension-accelerate": "2.0.2", - "dotenv": "16.6.1" + "dotenv": "^16.4.7" }, "devDependencies": { "@types/node": "22.15.32", "prisma": "6.18.0", - "tsx": "4.20.6", + "tsx": "^4.20.6", "typescript": "5.8.2" } } \ No newline at end of file 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/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/starter/package.json b/orm/starter/package.json index 645006af0ff9..3af607799f66 100644 --- a/orm/starter/package.json +++ b/orm/starter/package.json @@ -12,13 +12,13 @@ "@types/node": "22.18.12", "nodemon": "3.1.10", "prisma": "6.18.0", - "tsx": "4.20.6", + "tsx": "^4.20.6", "typescript": "5.8.2" }, "dependencies": { + "@prisma/adapter-pg": "6.18.0", "@prisma/client": "6.18.0", - "@prisma/extension-accelerate": "2.0.2", - "dotenv": "16.6.1" + "dotenv": "^16.4.7" }, "prettier": { "trailingComma": "all", @@ -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..c9464d2c4920 100644 --- a/orm/testing-express/README.md +++ b/orm/testing-express/README.md @@ -65,38 +65,27 @@ 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 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()) - -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 ``` @@ -112,7 +101,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 +160,9 @@ 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: - -```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 diff --git a/orm/testing-express/package.json b/orm/testing-express/package.json index 7ca822bd8105..47478ce0a1f6 100644 --- a/orm/testing-express/package.json +++ b/orm/testing-express/package.json @@ -14,8 +14,7 @@ "dependencies": { "@prisma/adapter-pg": "6.18.0", "@prisma/client": "6.18.0", - "@prisma/extension-accelerate": "2.0.2", - "dotenv": "16.6.1", + "dotenv": "^16.6.1", "express": "5.1.0", "jest-config": "29.7.0" }, @@ -26,14 +25,11 @@ "@types/supertest": "6.0.3", "jest": "29.7.0", "jest-environment-node": "29.7.0", - "nanoid": "5.1.6", + "nanoid": "5.1.5", "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/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) diff --git a/orm/typedsql/package.json b/orm/typedsql/package.json index ae3e9bdef6c5..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", - "tsx": "4.20.6" + "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)