From b79b6080d3bfd52295c39786ee244baf8ea5d6dd Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 02:55:18 +0600 Subject: [PATCH 01/10] feat: add kysley --- .../100-quickstart/100-kysely.mdx | 261 +++++++++++++----- 1 file changed, 193 insertions(+), 68 deletions(-) diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx index 1b2b1ff247..077621a10d 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx @@ -6,104 +6,226 @@ metaDescription: 'Get started with Kysely and Prisma Postgres by creating a type sidebar_custom_props: { badge: '10 min' } --- -[Kysely](https://kysely.dev) is a type-safe TypeScript SQL query builder that provides excellent TypeScript support and a fluent API for building SQL queries. In this guide, you'll learn how to connect Kysely to [Prisma Postgres](/postgres) and start querying your database with full type safety. +[Kysely](https://kysely.dev) is a type-safe TypeScript SQL query builder that provides TypeScript support and a fluent API for building SQL queries. In this guide, you'll learn how to connect Kysely to [Prisma Postgres](/postgres) and start querying your database with full type safety. ## Prerequisites -- **Node.js** - Version 14 or higher -- **TypeScript** - Version 4.6 or higher (5.4+ recommended for better type inference) -- A [Prisma Data Platform](https://console.prisma.io) account -- (Optional) **Kysely setup** - If you already have Kysely configured in your project, skip to [step 2](#2-get-your-direct-connection-string) +- Node.js Version `14` or higher +- TypeScript Version `4.6` or higher (`5.4`+ recommended for improved type inference, `5.9`+ for better compilation performance) +- Strict mode enabled in your `tsconfig.json` for Kysely's type safety -For detailed Kysely installation and configuration, see the [Kysely Getting started guide](https://kysely.dev/docs/getting-started). +:::tip -## 1. Create a Prisma Postgres database +For the most up-to-date installation and configuration details, see the [Kysely documentation](https://kysely.dev/docs/getting-started). -Follow these steps to create your Prisma Postgres database: +::: -1. Log in to [Prisma Data Platform](https://console.prisma.io) and open the Console. -2. In a workspace of your choice, click the **New project** button. -3. Type a name for your project in the **Name** field, e.g. `kysely-quickstart`. -4. In the **Prisma Postgres** section, click the **Get started** button. -5. In the **Region** dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia). -6. Click the **Create project** button. +## 1. Create a new project -At this point, you'll be redirected to the Database page where you will need to wait for a few seconds while the status of your database changes from **PROVISIONING** to **CONNECTED**. +Create a new directory for your project and initialize it with npm: -Once the green **CONNECTED** label appears, your database is ready to use! +```terminal +mkdir kysely-quickstart +cd kysely-quickstart +npm init -y +``` + +Install TypeScript and initialize it: + +```terminal +npm install --save-dev typescript +npx tsc --init +``` -## 2. Get your direct connection string +## 2. Configure TypeScript + +Kysely requires TypeScript's strict mode for proper type safety. Update your `tsconfig.json` file: + +```json file=tsconfig.json +{ + // ... + "compilerOptions": { + // ... + // add-start + "strict": true, + "allowImportingTsExtensions": true, + "noEmit": true + // add-end + // ... + } + // ... +} +``` -To connect to Prisma Postgres via direct TCP, you need to: +:::note -1. Open your project in the Prisma Console. -2. Navigate to your active Prisma Postgres instance. -3. Click the **API Keys** tab in the project's sidenav. -4. Click the **Create API key** button. -5. In the popup, provide a **Name** for the API key and click **Create**. -6. Copy the connection string starting with `postgres://`, this is your direct connection string. +The `strict: true` setting is **required** for Kysely's type safety to work correctly. -## 3. Create a new project +::: -Create a new directory for your project and initialize it: +In your `package.json`, set the `type` to `module`: + +```json +{ +// ... +// add-start +"type": "module" +// add-end +// ... +} +``` + +## 3. Create a Prisma Postgres database + +You can create a Prisma Postgres database using the `create-db` CLI tool. Follow these steps to create your Prisma Postgres database: ```terminal -mkdir kysely-quickstart -cd kysely-quickstart -npm init -y +npx create-db ``` -## 4. Configure Kysely with Prisma Postgres +Then the CLI tool should output: + +```terminal +β”Œ πŸš€ Creating a Prisma Postgres database +β”‚ +β”‚ Provisioning a temporary database in us-east-1... +β”‚ +β”‚ It will be automatically deleted in 24 hours, but you can claim it. +β”‚ +β—‡ Database created successfully! +β”‚ +β”‚ +● Database Connection +β”‚ +β”‚ +β”‚ Connection String: +β”‚ +β”‚ postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require +β”‚ +β”‚ +β—† Claim Your Database +β”‚ +β”‚ Keep your database for free: +β”‚ +β”‚ https://create-db.prisma.io/claim?CLAIM_CODE +β”‚ +β”‚ Database will be deleted on 11/18/2025, 1:55:39 AM if not claimed. +β”‚ +β”” +``` + +Create a `.env` file and add the connection string from the output: + +```env file=.env +DATABASE_URL="postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require" +``` -Create a database connection file that uses your Prisma Postgres connection string: +:::warning +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. -```typescript file=database.ts +::: + +The database created is temporary and will be deleted in 24 hours unless claimed. Claiming moves the database into your [Prisma Data Platform](https://console.prisma.io) account. Visit the claim URL from the output to keep your database. + +:::note + +To learn more about the `create-db` CLI tool, see the [create-db documentation](/postgres/introduction/npx-create-db). + +::: + +## 4. Install dependencies + +Install Kysely and the PostgreSQL driver: + +```terminal +npm install kysely pg dotenv +npm install --save-dev @types/pg tsx +``` + +**Package breakdown:** +- `kysely`: The type-safe SQL query builder +- `pg`: PostgreSQL driver for Node.js (required by Kysely's PostgresDialect) +- `dotenv`: Loads environment variables from `.env` file +- `@types/pg`: TypeScript type definitions for the pg driver +- `tsx`: TypeScript execution engine for running `.ts` files directly + +## 5. Define database types + +Create a `src/types.ts` file to define your database schema types: + +```typescript file=src/types.ts +import type { Generated } from "kysely"; + +export interface Database { + users: UsersTable; +} + +export interface UsersTable { + id: Generated; + email: string; + name: string | null; +} +``` + +## 6. Configure database connection + +Create a `src/database.ts` file to instantiate Kysely with your Prisma Postgres connection: + +```typescript file=src/database.ts +import 'dotenv/config' +import type { Database } from './types.ts' import { Pool } from 'pg' import { Kysely, PostgresDialect } from 'kysely' +// Parse DATABASE_URL into connection parameters +function parseConnectionString(url: string) { + const parsed = new URL(url) + return { + host: parsed.hostname, + port: parseInt(parsed.port), + user: parsed.username, + password: parsed.password, + database: parsed.pathname.slice(1), // Remove leading '/' + } +} + +const connectionParams = parseConnectionString(process.env.DATABASE_URL!) + const dialect = new PostgresDialect({ pool: new Pool({ - connectionString: process.env.DATABASE_URL, + ...connectionParams, + ssl: true, max: 10, }) }) -// Define your database interface -interface Database { - users: { - id: number - email: string - name: string | null - } - posts: { - id: number - title: string - content: string | null - published: boolean - author_id: number - } -} - +// Database interface is passed to Kysely's constructor, and from now on, Kysely +// knows your database structure. +// Dialect is passed to Kysely's constructor, and from now on, Kysely knows how +// to communicate with your database. export const db = new Kysely({ dialect, }) ``` -Create a `.env` file and add your Prisma Postgres connection string: +## 7. Run queries -```env file=.env -DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" -``` - -## 5. Use Kysely with Prisma Postgres +Create a `src/script.ts` file: -Now you can use Kysely to query your Prisma Postgres database: - -```typescript file=script.ts -import { db } from './database' +```typescript file=src/script.ts +import { db } from './database.ts' async function main() { + // Create the users table + await db.schema + .createTable('users') + .ifNotExists() + .addColumn('id', 'serial', (col) => col.primaryKey()) + .addColumn('email', 'varchar(255)', (col) => col.notNull().unique()) + .addColumn('name', 'varchar(255)') + .execute() + // Insert a user const user = await db .insertInto('users') @@ -136,16 +258,19 @@ main() }) ``` -## Next steps +Run the script: + +```terminal +npx tsx src/script.ts +``` -Now that you have Kysely connected to Prisma Postgres, you can: +You should receive the following output: -- **Learn more about Kysely** - Check out the [Kysely documentation](https://kysely.dev/docs/intro) for advanced query patterns -- **Explore migrations** - Learn about [Kysely migrations](https://kysely.dev/docs/migrations) for managing schema changes -- **Add more complex queries** - Explore [joins](https://kysely.dev/docs/category/join), [subqueries](https://kysely.dev/docs/examples/join/subquery-join), and [transactions](https://kysely.dev/docs/category/transactions) +```terminal +Created user: { id: 1, email: 'alice@prisma.io', name: 'Alice' } +All users: [ { id: 1, email: 'alice@prisma.io', name: 'Alice' } ] +``` -## More info +## Next steps -- [Kysely documentation](https://kysely.dev) -- [Prisma Postgres documentation](/postgres) -- [PostgreSQL driver documentation](https://node-postgres.com) +Learn more about Kysely in the [Kysely documentation](https://kysely.dev/docs/intro). From 10f9cfbb840afce4a14d0ab95e81c8978985fbe8 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 03:16:10 +0600 Subject: [PATCH 02/10] feat: add drizzle --- .../100-quickstart/100-kysely.mdx | 4 +- .../100-quickstart/200-drizzle-orm.mdx | 264 +++++++++--------- 2 files changed, 135 insertions(+), 133 deletions(-) diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx index 077621a10d..2ac28fc55b 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx @@ -10,8 +10,8 @@ sidebar_custom_props: { badge: '10 min' } ## Prerequisites -- Node.js Version `14` or higher -- TypeScript Version `4.6` or higher (`5.4`+ recommended for improved type inference, `5.9`+ for better compilation performance) +- Node.js version 14 or higher +- TypeScript version 4.6 or higher (5.4+ recommended for improved type inference, 5.9+ for better compilation performance) - Strict mode enabled in your `tsconfig.json` for Kysely's type safety :::tip diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx index c729d66565..9c0351695a 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx @@ -2,50 +2,26 @@ title: 'Use Prisma Postgres with Drizzle ORM' sidebar_label: 'Drizzle ORM' metaTitle: 'Quickstart: Drizzle ORM with Prisma Postgres (10 min)' -metaDescription: 'Get started with Drizzle ORM and Prisma Postgres by creating a lightweight, performant TypeScript ORM for your database.' +metaDescription: 'Get started with Drizzle ORM and Prisma Postgres.' sidebar_custom_props: { badge: '10 min' } --- -[Drizzle ORM](https://orm.drizzle.team) is a lightweight and performant TypeScript ORM with developer experience in mind. It provides a SQL-like syntax with full TypeScript support and excellent performance. In this guide, you'll learn how to connect Drizzle ORM to [Prisma Postgres](/postgres) and start building type-safe database queries. +[Drizzle ORM](https://orm.drizzle.team) is a TypeScript ORM. In this guide, you'll learn how to connect Drizzle ORM to [Prisma Postgres](/postgres). ## Prerequisites -- **Node.js** - Version 16 or higher -- **TypeScript** - Version 5.0 or higher -- A [Prisma Data Platform](https://console.prisma.io) account -- (Optional) **Drizzle ORM setup** - If you already have Drizzle configured in your project, skip to [step 2](#2-get-your-direct-connection-string) +- Node.js version 16 or higher +- TypeScript version 5.0 or higher -For detailed Drizzle ORM installation and configuration, see the [Drizzle ORM Getting started guide](https://orm.drizzle.team/docs/get-started-postgresql). +:::tip -## 1. Create a Prisma Postgres database +For the most up-to-date installation and configuration details, see the [Drizzle ORM documentation](https://orm.drizzle.team/docs/get-started). -Follow these steps to create your Prisma Postgres database: +::: -1. Log in to [Prisma Data Platform](https://console.prisma.io) and open the Console. -2. In a workspace of your choice, click the **New project** button. -3. Type a name for your project in the **Name** field, e.g. `drizzle-quickstart`. -4. In the **Prisma Postgres** section, click the **Get started** button. -5. In the **Region** dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia). -6. Click the **Create project** button. +## 1. Create a new project -At this point, you'll be redirected to the Database page where you will need to wait for a few seconds while the status of your database changes from **PROVISIONING** to **CONNECTED**. - -Once the green **CONNECTED** label appears, your database is ready to use! - -## 2. Get your direct connection string - -To connect to Prisma Postgres via direct TCP, you need to: - -1. Open your project in the Prisma Console. -2. Navigate to your active Prisma Postgres instance. -3. Click the **API Keys** tab in the project's sidenav. -4. Click the **Create API key** button. -5. In the popup, provide a **Name** for the API key and click **Create**. -6. Copy the connection string starting with `postgres://`, this is your direct connection string. - -## 3. Create a new project - -Create a new directory for your project and initialize it: +Create a new directory for your project and initialize it with npm: ```terminal mkdir drizzle-quickstart @@ -53,141 +29,167 @@ cd drizzle-quickstart npm init -y ``` -## 4. Configure Drizzle ORM with Prisma Postgres +Install TypeScript and initialize it: -Define your database schema using Drizzle's schema definition: +```terminal +npm install --save-dev typescript +npx tsc --init +``` +In your `package.json`, set the `type` to `module`: -```typescript file=schema.ts -import { pgTable, serial, text, varchar, boolean, timestamp, integer } from 'drizzle-orm/pg-core' -import { relations } from 'drizzle-orm' +```json file=package.json +{ + // ... + // add-start + "type": "module" + // add-end + // ... +} +``` -export const users = pgTable('users', { - id: serial('id').primaryKey(), - email: varchar('email', { length: 255 }).notNull().unique(), - name: text('name'), - createdAt: timestamp('created_at').defaultNow().notNull(), -}) +## 2. Create a Prisma Postgres database -export const posts = pgTable('posts', { - id: serial('id').primaryKey(), - title: varchar('title', { length: 255 }).notNull(), - content: text('content'), - published: boolean('published').default(false).notNull(), - authorId: integer('author_id') - .notNull() - .references(() => users.id, { onDelete: 'cascade' }), - createdAt: timestamp('created_at').defaultNow().notNull(), -}) +You can create a Prisma Postgres database using the `create-db` CLI tool. Follow these steps to create your Prisma Postgres database: -// Define relations -export const usersRelations = relations(users, ({ many }) => ({ - posts: many(posts), -})) - -export const postsRelations = relations(posts, ({ one }) => ({ - author: one(users, { - fields: [posts.authorId], - references: [users.id], - }), -})) +```terminal +npx create-db ``` -Configure Drizzle Kit with your Prisma Postgres connection string: - -```typescript file=drizzle.config.ts -import { defineConfig } from 'drizzle-kit' +Then the CLI tool should output: -export default defineConfig({ - schema: './schema.ts', - out: './drizzle', - dialect: 'postgresql', - dbCredentials: { - url: process.env.DATABASE_URL!, - }, -}) +```terminal +β”Œ πŸš€ Creating a Prisma Postgres database +β”‚ +β”‚ Provisioning a temporary database in us-east-1... +β”‚ +β”‚ It will be automatically deleted in 24 hours, but you can claim it. +β”‚ +β—‡ Database created successfully! +β”‚ +β”‚ +● Database Connection +β”‚ +β”‚ +β”‚ Connection String: +β”‚ +β”‚ postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require +β”‚ +β”‚ +β—† Claim Your Database +β”‚ +β”‚ Keep your database for free: +β”‚ +β”‚ https://create-db.prisma.io/claim?CLAIM_CODE +β”‚ +β”‚ Database will be deleted on 11/18/2025, 1:55:39 AM if not claimed. +β”‚ +β”” ``` -Create a `.env` file and add your Prisma Postgres connection string: +Create a `.env` file and add the connection string from the output: ```env file=.env -DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" +DATABASE_URL="postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require" ``` -Create a database connection file: +:::warning -```typescript file=db.ts -import { drizzle } from 'drizzle-orm/node-postgres' -import { Pool } from 'pg' -import * as schema from './schema' +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. -const pool = new Pool({ - connectionString: process.env.DATABASE_URL, -}) +::: -export const db = drizzle({ client: pool, schema }) -``` +The database created is temporary and will be deleted in 24 hours unless claimed. Claiming moves the database into your [Prisma Data Platform](https://console.prisma.io) account. Visit the claim URL from the output to keep your database. -## 5. Use Drizzle ORM with Prisma Postgres +:::note -Generate and push your schema to the database: +To learn more about the `create-db` CLI tool, see the [create-db documentation](/postgres/introduction/npx-create-db). + +::: + +## 3. Install dependencies + +Install Drizzle ORM and the PostgreSQL driver: ```terminal -npx drizzle-kit push +npm install drizzle-orm pg dotenv +npm install --save-dev drizzle-kit @types/pg tsx ``` -Now you can use Drizzle ORM to query your Prisma Postgres database: +**Package breakdown:** +- `drizzle-orm`: The lightweight TypeScript ORM +- `pg`: PostgreSQL driver for Node.js +- `dotenv`: Loads environment variables from `.env` file +- `drizzle-kit`: CLI tool for migrations and schema management +- `@types/pg`: TypeScript type definitions for the pg driver +- `tsx`: TypeScript execution engine for running `.ts` files directly -```typescript file=script.ts -import { db } from './db' -import { users, posts } from './schema' -import { eq } from 'drizzle-orm' +## 4. Run a query -async function main() { - // Insert a user - const [user] = await db - .insert(users) - .values({ - name: 'Alice', - email: 'alice@prisma.io', - }) - .returning() - - console.log('Created user:', user) - - // Query users with their posts - const usersWithPosts = await db.query.users.findMany({ - with: { - posts: true, - }, - }) +Create a `src/script.ts` file: + +```typescript file=src/script.ts +import 'dotenv/config' +import { drizzle } from 'drizzle-orm/node-postgres' +import { Pool } from 'pg' + +const pool = new Pool({ + connectionString: process.env.DATABASE_URL, +}) + +const db = drizzle({ client: pool }) - console.log('Users with posts:', JSON.stringify(usersWithPosts, null, 2)) +async function main() { + const result = await db.execute('select 1') + console.log('Query result:', result) } main() - .then(() => { - console.log('Done!') - process.exit(0) + .then(async () => { + await pool.end() + console.log('Connection closed') }) - .catch((error) => { + .catch(async (error) => { console.error('Error:', error) + await pool.end() process.exit(1) }) ``` -## Next steps +Run the script: -Now that you have Drizzle ORM connected to Prisma Postgres, you can: +```terminal +npx tsx src/script.ts +``` -- **Learn more about Drizzle** - Check out the [Drizzle ORM documentation](https://orm.drizzle.team/docs/overview) for advanced features -- **Explore queries** - Learn about [select queries](https://orm.drizzle.team/docs/select), [joins](https://orm.drizzle.team/docs/joins), and [transactions](https://orm.drizzle.team/docs/transactions) -- **Manage migrations** - Explore [Drizzle Kit migrations](https://orm.drizzle.team/docs/migrations) for schema management -- **Use relational queries** - Take advantage of [Drizzle's relational query API](https://orm.drizzle.team/docs/rqb) for cleaner code +You should receive output similar to: -## More info +```terminal +Query result: Result { + command: 'SELECT', + rowCount: 1, + oid: null, + rows: [ { '?column?': 1 } ], + fields: [ + Field { + name: '?column?', + tableID: 0, + columnID: 0, + dataTypeID: 23, + dataTypeSize: 4, + dataTypeModifier: -1, + format: 'text' + } + ], + _parsers: [ [Function: parseInteger] ], + _types: { getTypeParser: [Function: getTypeParser] }, + RowCtor: null, + rowAsArray: false, + _prebuiltEmptyResultObject: { '?column?': null } +} +Connection closed +``` + +## Next steps -- [Drizzle ORM documentation](https://orm.drizzle.team) -- [Drizzle ORM GitHub repository](https://github.com/drizzle-team/drizzle-orm) -- [Prisma Postgres documentation](/postgres) -- [Drizzle Kit documentation](https://orm.drizzle.team/kit-docs/overview) +Learn more about Drizzle ORM in the [Drizzle ORM documentation](https://orm.drizzle.team/docs/get-started). From f14117b2a412789ae7197374afead3df47147c95 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 03:44:33 +0600 Subject: [PATCH 03/10] feat: add typeorm --- .../100-quickstart/100-kysely.mdx | 8 +- .../100-quickstart/200-drizzle-orm.mdx | 8 +- .../100-quickstart/300-typeorm.mdx | 258 +++++++++--------- 3 files changed, 129 insertions(+), 145 deletions(-) diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx index 2ac28fc55b..314a2a0be7 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx @@ -14,12 +14,6 @@ sidebar_custom_props: { badge: '10 min' } - TypeScript version 4.6 or higher (5.4+ recommended for improved type inference, 5.9+ for better compilation performance) - Strict mode enabled in your `tsconfig.json` for Kysely's type safety -:::tip - -For the most up-to-date installation and configuration details, see the [Kysely documentation](https://kysely.dev/docs/getting-started). - -::: - ## 1. Create a new project Create a new directory for your project and initialize it with npm: @@ -273,4 +267,4 @@ All users: [ { id: 1, email: 'alice@prisma.io', name: 'Alice' } ] ## Next steps -Learn more about Kysely in the [Kysely documentation](https://kysely.dev/docs/intro). +You've successfully connected Kysely to Prisma Postgres! For more advanced features like schemas, migrations, and complex queries, see the [Kysely documentation](https://kysely.dev/docs/intro). diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx index 9c0351695a..300882ca06 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx @@ -13,12 +13,6 @@ sidebar_custom_props: { badge: '10 min' } - Node.js version 16 or higher - TypeScript version 5.0 or higher -:::tip - -For the most up-to-date installation and configuration details, see the [Drizzle ORM documentation](https://orm.drizzle.team/docs/get-started). - -::: - ## 1. Create a new project Create a new directory for your project and initialize it with npm: @@ -192,4 +186,4 @@ Connection closed ## Next steps -Learn more about Drizzle ORM in the [Drizzle ORM documentation](https://orm.drizzle.team/docs/get-started). +You've successfully connected Drizzle ORM to Prisma Postgres! For more advanced features like schemas, migrations, and queries, see the [Drizzle ORM documentation](https://orm.drizzle.team/docs/get-started). diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx index ff923f02cc..4a310d2624 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx @@ -6,180 +6,176 @@ metaDescription: 'Get started with TypeORM and Prisma Postgres by connecting you sidebar_custom_props: { badge: '10 min' } --- -[TypeORM](https://typeorm.io) is a feature-rich ORM that supports both Active Record and Data Mapper patterns, providing flexibility in how you structure your database code. In this guide, you'll learn how to connect TypeORM to [Prisma Postgres](/postgres) and start building type-safe database applications. +[TypeORM](https://typeorm.io) is a TypeScript ORM. In this guide, you'll learn how to connect TypeORM to [Prisma Postgres](/postgres). ## Prerequisites -- **Node.js** - Version 16 or higher -- **TypeScript** - Version 4.5 or higher -- A [Prisma Data Platform](https://console.prisma.io) account -- (Optional) **TypeORM setup** - If you already have TypeORM configured in your project, skip to [step 2](#2-get-your-direct-connection-string) +- Node.js version 16 or higher +- TypeScript version 4.5 or higher -For detailed TypeORM installation and configuration, see the [TypeORM Getting started guide](https://typeorm.io/docs/getting-started/). +## 1. Generate a TypeORM project -## 1. Create a Prisma Postgres database +Use the TypeORM CLI to generate a starter project: -Follow these steps to create your Prisma Postgres database: +```terminal +npx typeorm init --name typeorm-quickstart --database postgres +``` -1. Log in to [Prisma Data Platform](https://console.prisma.io) and open the Console. -2. In a workspace of your choice, click the **New project** button. -3. Type a name for your project in the **Name** field, e.g. `typeorm-quickstart`. -4. In the **Prisma Postgres** section, click the **Get started** button. -5. In the **Region** dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia). -6. Click the **Create project** button. +This command will generate a new project with the following structure: -At this point, you'll be redirected to the Database page where you will need to wait for a few seconds while the status of your database changes from **PROVISIONING** to **CONNECTED**. +``` +typeorm-quickstart +β”œβ”€β”€ src +β”‚ β”œβ”€β”€ entity +β”‚ β”‚ └── User.ts # Sample entity +β”‚ β”œβ”€β”€ migration # Migrations folder +β”‚ β”œβ”€β”€ data-source.ts # Data source configuration +β”‚ └── index.ts # Application entry point +β”œβ”€β”€ .gitignore +β”œβ”€β”€ package.json +β”œβ”€β”€ README.md +└── tsconfig.json +``` -Once the green **CONNECTED** label appears, your database is ready to use! +## 2. Install dependencies -## 2. Get your direct connection string +Navigate to the project directory and install dependencies: -To connect to Prisma Postgres via direct TCP, you need to: +```terminal +cd typeorm-quickstart +npm install +``` -1. Open your project in the Prisma Console. -2. Navigate to your active Prisma Postgres instance. -3. Click the **API Keys** tab in the project's sidenav. -4. Click the **Create API key** button. -5. In the popup, provide a **Name** for the API key and click **Create**. -6. Copy the connection string starting with `postgres://`, this is your direct connection string. +Install dotenv to load environment variables: -## 3. Configure TypeORM with Prisma Postgres +```terminal +npm install dotenv +``` -Update your TypeORM DataSource configuration to use your Prisma Postgres connection string. In your `data-source.ts` (or equivalent configuration file): +## 3. Create a Prisma Postgres database -```typescript file=data-source.ts -import "reflect-metadata" -import { DataSource } from "typeorm" -import { User } from "./entity/User" -import { Post } from "./entity/Post" +You can create a Prisma Postgres database using the `create-db` CLI tool. Follow these steps to create your Prisma Postgres database: -export const AppDataSource = new DataSource({ - type: "postgres", - url: process.env.DATABASE_URL, // Your Prisma Postgres connection string - synchronize: true, // Set to false in production - logging: false, - entities: [User, Post], - migrations: [], - subscribers: [], -}) +```terminal +npx create-db ``` -Create a `.env` file and add your Prisma Postgres connection string: +Then the CLI tool should output: -```env file=.env -DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" +```terminal +β”Œ πŸš€ Creating a Prisma Postgres database +β”‚ +β”‚ Provisioning a temporary database in us-east-1... +β”‚ +β”‚ It will be automatically deleted in 24 hours, but you can claim it. +β”‚ +β—‡ Database created successfully! +β”‚ +β”‚ +● Database Connection +β”‚ +β”‚ +β”‚ Connection String: +β”‚ +β”‚ postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require +β”‚ +β”‚ +β—† Claim Your Database +β”‚ +β”‚ Keep your database for free: +β”‚ +β”‚ https://create-db.prisma.io/claim?CLAIM_CODE +β”‚ +β”‚ Database will be deleted on 11/18/2025, 1:55:39 AM if not claimed. +β”‚ +β”” ``` -:::tip - -For production applications, set `synchronize: false` and use [TypeORM migrations](https://typeorm.io/docs/migrations/setup) to manage schema changes safely. - -::: - -## 4. Define your entities +Create a `.env` file and add the connection string from the output: -Create your TypeORM entities as usual. Here's an example with User and Post entities: +```env file=.env +DATABASE_URL="postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require" +``` -```typescript file=entity/User.ts -import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm" -import { Post } from "./Post" +:::warning -@Entity() -export class User { - @PrimaryGeneratedColumn() - id: number +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. - @Column({ unique: true }) - email: string +::: - @Column({ nullable: true }) - name: string +The database created is temporary and will be deleted in 24 hours unless claimed. Claiming moves the database into your [Prisma Data Platform](https://console.prisma.io) account. Visit the claim URL from the output to keep your database. - @OneToMany(() => Post, (post) => post.author) - posts: Post[] -} -``` +:::note -```typescript file=entity/Post.ts -import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm" -import { User } from "./User" +To learn more about the `create-db` CLI tool, see the [create-db documentation](/postgres/introduction/npx-create-db). -@Entity() -export class Post { - @PrimaryGeneratedColumn() - id: number +::: - @Column() - title: string +## 4. Configure database connection - @Column({ type: "text", nullable: true }) - content: string +Update the `src/data-source.ts` file to use your Prisma Postgres connection: - @Column({ default: false }) - published: boolean +```typescript file=src/data-source.ts +import "reflect-metadata" +// add-start +import "dotenv/config"; +// add-end +import { DataSource } from "typeorm" +import { User } from "./entity/User" - @ManyToOne(() => User, (user) => user.posts) - author: User +// add-start +// Parse DATABASE_URL into connection parameters +function parseConnectionString(url: string) { + const parsed = new URL(url) + return { + host: parsed.hostname, + port: parseInt(parsed.port), + username: parsed.username, + password: parsed.password, + database: parsed.pathname.slice(1), // Remove leading '/' + } } -``` +// add-end +const connectionParams = parseConnectionString(process.env.DATABASE_URL!) -For more information on defining entities, see the [TypeORM Entities documentation](https://typeorm.io/docs/entity/entities). +export const AppDataSource = new DataSource({ + type: "postgres", + // delete-start + host: "localhost", + port: 5432, + username: "test", + password: "test", + database: "test", + // delete-end + // add-start + ...connectionParams, + ssl: true, + // add-end + synchronize: true, + logging: false, + entities: [User], + migrations: [], + subscribers: [], +}) +``` -## 5. Initialize and use TypeORM +## 5. Run the application -Initialize your DataSource and start querying: +Start the application: -```typescript file=index.ts -import "reflect-metadata" -import { AppDataSource } from "./data-source" -import { User } from "./entity/User" -import { Post } from "./entity/Post" - -AppDataSource.initialize() - .then(async () => { - console.log("Connected to Prisma Postgres!") - - // Create a user with a post - const user = new User() - user.email = "alice@prisma.io" - user.name = "Alice" - await AppDataSource.manager.save(user) - - const post = new Post() - post.title = "Hello World" - post.content = "This is my first post!" - post.published = true - post.author = user - await AppDataSource.manager.save(post) - - console.log("Created user and post!") - - // Query users with their posts - const users = await AppDataSource.getRepository(User).find({ - relations: { - posts: true, - }, - }) - - console.log("Users with posts:", JSON.stringify(users, null, 2)) - }) - .catch((error) => console.log("Error:", error)) +```terminal +npm start ``` -Run your application: +You should see output indicating the connection was successful and a new user was inserted into the database: ```terminal -npx tsx index.ts +Inserting a new user into the database... +Saved a new user with id: 1 +Loading users from the database... +Loaded users: [ User { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 } ] ``` ## Next steps -Now that you have TypeORM connected to Prisma Postgres, you can: - -- **Learn more about TypeORM** - Check out the [TypeORM documentation](https://typeorm.io/docs/) for comprehensive guides - -## More info - -- [TypeORM documentation](https://typeorm.io) -- [Prisma Postgres documentation](/postgres) -- [TypeORM PostgreSQL driver documentation](https://typeorm.io/docs/drivers/postgres/) +You've successfully connected TypeORM to Prisma Postgres! For more advanced features like entities, migrations, and queries, see the [TypeORM documentation](https://typeorm.io). From e3d027358b25fbd2caadf5808f2ae11ee383ff4c Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 04:01:38 +0600 Subject: [PATCH 04/10] fix: clean-up --- .../100-quickstart/100-kysely.mdx | 1 - .../100-quickstart/200-drizzle-orm.mdx | 1 - .../100-quickstart/300-typeorm.mdx | 6 +- .../100-quickstart/50-prisma-orm.mdx | 80 ++++--------------- .../225-import-from-existing-database.mdx | 14 ---- .../200-import-from-existing-database.mdx | 2 +- sidebars.ts | 12 --- static/_redirects | 1 + 8 files changed, 21 insertions(+), 96 deletions(-) delete mode 100644 content/250-postgres/100-introduction/225-import-from-existing-database.mdx diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx index 314a2a0be7..65d686208f 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/100-kysely.mdx @@ -3,7 +3,6 @@ title: 'Use Prisma Postgres with Kysely' sidebar_label: 'Kysely' metaTitle: 'Quickstart: Kysely with Prisma Postgres (10 min)' metaDescription: 'Get started with Kysely and Prisma Postgres by creating a type-safe SQL query builder for your database.' -sidebar_custom_props: { badge: '10 min' } --- [Kysely](https://kysely.dev) is a type-safe TypeScript SQL query builder that provides TypeScript support and a fluent API for building SQL queries. In this guide, you'll learn how to connect Kysely to [Prisma Postgres](/postgres) and start querying your database with full type safety. diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx index 300882ca06..7066de2857 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/200-drizzle-orm.mdx @@ -3,7 +3,6 @@ title: 'Use Prisma Postgres with Drizzle ORM' sidebar_label: 'Drizzle ORM' metaTitle: 'Quickstart: Drizzle ORM with Prisma Postgres (10 min)' metaDescription: 'Get started with Drizzle ORM and Prisma Postgres.' -sidebar_custom_props: { badge: '10 min' } --- [Drizzle ORM](https://orm.drizzle.team) is a TypeScript ORM. In this guide, you'll learn how to connect Drizzle ORM to [Prisma Postgres](/postgres). diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx index 4a310d2624..bbcc4469df 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/300-typeorm.mdx @@ -3,7 +3,6 @@ title: 'Use Prisma Postgres with TypeORM' sidebar_label: 'TypeORM' metaTitle: 'Quickstart: TypeORM with Prisma Postgres (10 min)' metaDescription: 'Get started with TypeORM and Prisma Postgres by connecting your TypeScript ORM to a managed PostgreSQL database.' -sidebar_custom_props: { badge: '10 min' } --- [TypeORM](https://typeorm.io) is a TypeScript ORM. In this guide, you'll learn how to connect TypeORM to [Prisma Postgres](/postgres). @@ -135,8 +134,9 @@ function parseConnectionString(url: string) { database: parsed.pathname.slice(1), // Remove leading '/' } } -// add-end + const connectionParams = parseConnectionString(process.env.DATABASE_URL!) +// add-end export const AppDataSource = new DataSource({ type: "postgres", @@ -178,4 +178,4 @@ Loaded users: [ User { id: 1, firstName: 'Timber', lastName: 'Saw', age: 25 } ] ## Next steps -You've successfully connected TypeORM to Prisma Postgres! For more advanced features like entities, migrations, and queries, see the [TypeORM documentation](https://typeorm.io). +You've successfully connected TypeORM to Prisma Postgres! For more advanced features like entities, migrations, and queries, see the [TypeORM documentation](https://typeorm.io/docs/getting-started). diff --git a/content/100-getting-started/03-prisma-postgres/100-quickstart/50-prisma-orm.mdx b/content/100-getting-started/03-prisma-postgres/100-quickstart/50-prisma-orm.mdx index d774affd78..d7bc02afd6 100644 --- a/content/100-getting-started/03-prisma-postgres/100-quickstart/50-prisma-orm.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-quickstart/50-prisma-orm.mdx @@ -3,7 +3,6 @@ title: 'Use Prisma Postgres with Prisma ORM' sidebar_label: 'Prisma ORM' metaTitle: 'Quickstart: Prisma ORM with Prisma Postgres (5 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to Prisma Postgres and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '5 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' @@ -17,37 +16,11 @@ import NextSteps from '../../_components/_next-steps.mdx' -## 1. Create a Prisma Postgres database - -Follow these steps to create your Prisma Postgres database: - -1. Log in to [Prisma Data Platform](https://console.prisma.io) and open the Console. -2. In a workspace of your choice, click the **New project** button. -3. Type a name for your project in the **Name** field, e.g. `hello-ppg`. -4. In the **Prisma Postgres** section, click the **Get started** button. -5. In the **Region** dropdown, select the region that's closest to your current location, e.g. US East (N. Virginia). -6. Click the **Create project** button. - -At this point, you'll be redirected to the Database page where you will need to wait for a few seconds while the status of your database changes from **PROVISIONING** to **CONNECTED**. - -Once the green **CONNECTED** label appears, your database is ready to use! - -## 2. Get your direct connection string - -To connect to Prisma Postgres via direct TCP, you need to: - -1. Open your project in the Prisma Console. -2. Navigate to your active Prisma Postgres instance. -3. Click the **API Keys** tab in the project's sidenav. -4. Click the **Create API key** button. -5. In the popup, provide a **Name** for the API key and click **Create**. -6. Copy the connection string starting with `postgres://`, this is your direct connection string. - -## 3. Create a new project +## 1. Create a new project -## 4. Install required dependencies +## 2. Install required dependencies Install the packages needed for this quickstart: @@ -63,7 +36,7 @@ Here's what each package does: - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database - **`dotenv`** - Loads environment variables from your `.env` file -## 5. Configure ESM support +## 3. Configure ESM support Update `tsconfig.json` for ESM compatibility: @@ -90,49 +63,28 @@ Update `package.json` to enable ESM: } ``` -## 6. Initialize Prisma ORM +## 4. Initialize Prisma ORM and create a Prisma Postgres database -You can now invoke the Prisma CLI by prefixing it with `npx`: +Next, set up your Prisma ORM project by creating your [Prisma Schema](/orm/prisma-schema) file with the following command: ```terminal -npx prisma +npx prisma init --db --output ../generated/prisma ``` -Next, set up your Prisma ORM project by creating your [Prisma Schema](/orm/prisma-schema) file with the following command: +:::info -```terminal -npx prisma init --output ../generated/prisma -``` +You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database. + +::: This command does a few things: - Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models +- Creates a new Prisma Postgres database (when using `--db` flag) - Creates a `.env` file in the root directory for environment variables - Generates the Prisma Client in the `generated/prisma/` directory - Creates a `prisma.config.ts` file for Prisma configuration -Add your Prisma Postgres direct connection string to the `.env` file: - -```env file=.env -DATABASE_URL="postgres://your-connection-string" -``` - -The generated `prisma.config.ts` file looks like this: - -```typescript file=prisma.config.ts -import { defineConfig, env } from 'prisma/config' - -export default defineConfig({ - schema: 'prisma/schema.prisma', - migrations: { - path: 'prisma/migrations', - }, - datasource: { - url: env('DATABASE_URL'), - }, -}) -``` - Add `dotenv` to `prisma.config.ts` so that Prisma can load environment variables from your `.env` file: ```typescript file=prisma.config.ts @@ -165,7 +117,7 @@ datasource db { } ``` -## 7. Define your data model +## 5. Define your data model Open `prisma/schema.prisma` and add the following models: @@ -198,7 +150,7 @@ model Post { //add-end ``` -## 8. Create and apply your first migration +## 6. Create and apply your first migration Create your first migration to set up the database tables: @@ -214,7 +166,7 @@ Now run the following command to generate the Prisma Client: npx prisma generate ``` -## 9. Instantiate Prisma Client +## 7. Instantiate Prisma Client Now that you have all the dependencies installed, you can instantiate Prisma Client. You need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: @@ -231,7 +183,7 @@ const prisma = new PrismaClient({ adapter }) export { prisma } ``` -## 10. Write your first query +## 8. Write your first query Create a `script.ts` file to test your setup: @@ -286,7 +238,7 @@ npx tsx script.ts You should see the created user and all users printed to the console! -## 11. Explore your data with Prisma Studio +## 9. Explore your data with Prisma Studio diff --git a/content/250-postgres/100-introduction/225-import-from-existing-database.mdx b/content/250-postgres/100-introduction/225-import-from-existing-database.mdx deleted file mode 100644 index 7420adf337..0000000000 --- a/content/250-postgres/100-introduction/225-import-from-existing-database.mdx +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: 'Import data from an existing PostgreSQL database' -sidebar_label: 'Import from existing database' -metaTitle: 'Import from existing Postgres database into Prisma Postgres' -metaDescription: 'Learn how to import data from an existing database into Prisma Postgres.' -tocDepth: 3 -toc: true -search: true ---- - -If you have an existing database and want to import your data into Prisma Postgres, you can use one of our guides: - -- [Import from PostgreSQL](/getting-started/prisma-postgres/import-from-existing-database-postgresql) -- [Import from MySQL](/getting-started/prisma-postgres/import-from-existing-database-mysql) \ No newline at end of file diff --git a/content/250-postgres/50-getting-started/200-import-from-existing-database.mdx b/content/250-postgres/50-getting-started/200-import-from-existing-database.mdx index e72aa23fdf..9d4cdd5ecf 100644 --- a/content/250-postgres/50-getting-started/200-import-from-existing-database.mdx +++ b/content/250-postgres/50-getting-started/200-import-from-existing-database.mdx @@ -8,4 +8,4 @@ hide_table_of_contents: true import { Redirect } from '@docusaurus/router'; - \ No newline at end of file + \ No newline at end of file diff --git a/sidebars.ts b/sidebars.ts index da2972ced2..bb75dc1400 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -254,33 +254,21 @@ const sidebars: SidebarsConfig = { type: "doc", id: "getting-started/prisma-postgres/quickstart/prisma-orm", label: "Prisma ORM", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-postgres/quickstart/kysely", label: "Kysely", - customProps: { - badge: "10 Min", - }, }, { type: "doc", id: "getting-started/prisma-postgres/quickstart/drizzle-orm", label: "Drizzle ORM", - customProps: { - badge: "10 Min", - }, }, { type: "doc", id: "getting-started/prisma-postgres/quickstart/typeorm", label: "TypeORM", - customProps: { - badge: "10 Min", - }, }, ], }, diff --git a/static/_redirects b/static/_redirects index c90e320673..875bdece14 100644 --- a/static/_redirects +++ b/static/_redirects @@ -821,5 +821,6 @@ /getting-started/prisma-postgres/upgrade-from-early-access* /docs/postgres/getting-started +/postgres/introduction/import-from-existing-database* /docs/getting-started/prisma-postgres/import-from-existing-database-postgresql ### NO REDIRECTS BELOW THIS LINE. ADD REDIRECTS ABOVE THIS SECTION ### From eb0d9ed4cec93b826a67ea70d5b95903cba40d12 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 05:15:51 +0600 Subject: [PATCH 05/10] fix: update prisma init command changes --- .../03-prisma-postgres/100-from-the-cli.mdx | 45 ++++++-- ...15-import-from-existing-database-mysql.mdx | 1 - .../200-prisma-cli-reference.mdx | 94 ++++++++++++++-- .../350-integrations/100-netlify.mdx | 2 +- .../30-docs-components/01-mdx-examples.mdx | 105 ++++++++++++------ 5 files changed, 191 insertions(+), 56 deletions(-) diff --git a/content/100-getting-started/03-prisma-postgres/100-from-the-cli.mdx b/content/100-getting-started/03-prisma-postgres/100-from-the-cli.mdx index 9d3e6275ff..8c8c91ccb6 100644 --- a/content/100-getting-started/03-prisma-postgres/100-from-the-cli.mdx +++ b/content/100-getting-started/03-prisma-postgres/100-from-the-cli.mdx @@ -31,30 +31,57 @@ npx prisma@latest init --db ```code no-copy wrap -Success! Your Prisma Postgres database is ready βœ… +βœ“ Select an authentication method Google +Authenticating to Prisma Platform via browser. -We created an initial schema.prisma file and a .env file with your DATABASE_URL environment variable already set. +Visit the following URL in your browser to authenticate: +https://console.prisma.io/auth/cli?state=eyJjb6ll... + +Successfully authenticated as jon@doe.com. +Let's set up your Prisma Postgres database! +βœ“ Select your region: ap-southeast-1 - Asia Pacific (Singapore) +βœ“ Enter a project name: My Prisma Project +βœ“ Success! Your Prisma Postgres database is ready βœ… + +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: --- Next steps --- Go to https://pris.ly/ppg-init for detailed instructions. -1. Define your database schema -Open the schema.prisma file and define your first models. Check the docs if you need inspiration: https://pris.ly/ppg-init +1. Install the Postgres adapter +npm install @prisma/adapter-pg + +...and add it to your Prisma Client instance: + +import { PrismaClient } from "./generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const connectionString = `${process.env.DATABASE_URL}`; + +const adapter = new PrismaPg({ connectionString }); +const prisma = new PrismaClient({ adapter }); 2. Apply migrations Run the following command to create and apply a migration: -npx prisma migrate dev --name init +npx prisma migrate dev 3. Manage your data -View and edit your data locally by running this command: +View and edit your data locally by running this command: npx prisma studio -... or online in Console: -https://console.prisma.io/cliwxim5p005xqh0g3mvqpyak/cm6kw97t801ijzhvfwz4a0my3/cm6kw97ta01ikzhvf965vresv/studio +...or online in Console: +https://console.prisma.io/$path 4. Send queries from your app -To access your database from a JavaScript/TypeScript app, you need to use Prisma ORM. Go here for step-by-step instructions: https://pris.ly/ppg-init +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 +For more info, visit the Prisma Postgres docs: https://pris.ly/ppg-docs ``` diff --git a/content/100-getting-started/03-prisma-postgres/115-import-from-existing-database-mysql.mdx b/content/100-getting-started/03-prisma-postgres/115-import-from-existing-database-mysql.mdx index 0d009ba206..97bfeade5e 100644 --- a/content/100-getting-started/03-prisma-postgres/115-import-from-existing-database-mysql.mdx +++ b/content/100-getting-started/03-prisma-postgres/115-import-from-existing-database-mysql.mdx @@ -189,7 +189,6 @@ datasource db { // add-start provider = "postgres" // add-end - url = env("DATABASE_URL") } ``` diff --git a/content/200-orm/500-reference/200-prisma-cli-reference.mdx b/content/200-orm/500-reference/200-prisma-cli-reference.mdx index 8dd4fff307..20fb5b52de 100644 --- a/content/200-orm/500-reference/200-prisma-cli-reference.mdx +++ b/content/200-orm/500-reference/200-prisma-cli-reference.mdx @@ -155,17 +155,27 @@ prisma init ```code no-copy wrap -βœ” Your Prisma schema was created at prisma/schema.prisma. - You can now open it in your favorite editor. +npx prisma init -Next steps: -1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started -2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql, sqlite, sqlserver, mongodb or cockroachdb. -3. Run prisma db pull to turn your database schema into a Prisma schema. -4. Run prisma generate to generate Prisma Client. You can then start querying your database. +Initialized Prisma in your project -More information in our documentation: -https://pris.ly/d/getting-started + prisma/ + schema.prisma + prisma.config.ts + +Next, choose how you want to set up your database: + +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in `prisma.config.ts` + 2. Run `npx prisma db pull` to introspect your database. + +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + + Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema. + +Learn more: https://pris.ly/getting-started ``` @@ -184,10 +194,76 @@ The command output contains helpful information on how to use the generated file **Run `prisma init --db`** + + + + ```terminal prisma init --db ``` + + + + +```code no-copy wrap +βœ“ Select an authentication method Google +Authenticating to Prisma Platform via browser. + +Visit the following URL in your browser to authenticate: +https://console.prisma.io/auth/cli?state=eyJjb6ll... + +Successfully authenticated as amanyoyoyo@gmail.com. +Let's set up your Prisma Postgres database! +βœ“ Select your region: ap-southeast-1 - Asia Pacific (Singapore) +βœ“ Enter a project name: My Prisma Project +βœ“ Success! Your Prisma Postgres database is ready βœ… + +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: + +--- Next steps --- + +Go to https://pris.ly/ppg-init for detailed instructions. + +1. Install the Postgres adapter +npm install @prisma/adapter-pg + +...and add it to your Prisma Client instance: + +import { PrismaClient } from "./generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const connectionString = `${process.env.DATABASE_URL}`; + +const adapter = new PrismaPg({ connectionString }); +const prisma = new PrismaClient({ adapter }); + +2. Apply migrations +Run the following command to create and apply a migration: +npx prisma migrate dev + +3. Manage your data +View and edit your data locally by running this command: +npx prisma studio + +...or online in Console: +https://console.prisma.io/cmhyn0uwl0q6903foel16ff31/cmhyn143t074tyLfoezs684ag/cmhyn143t074uylfon8hfre5z/studio + +4. 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 +For more info, visit the Prisma Postgres docs: https://pris.ly/ppg-docs +``` + + + + + The command creates a new [Prisma Postgres](https://www.prisma.io/postgres) instance. Note that it requires you to be authenticated with the [PDP Console](https://console.prisma.io), If you run it for the first time without being authenticated, the command will open the browser for you to log into Console. **Run `prisma init --prompt "Simple habit tracker application"`** diff --git a/content/250-postgres/350-integrations/100-netlify.mdx b/content/250-postgres/350-integrations/100-netlify.mdx index 9cbd243363..06a1353719 100644 --- a/content/250-postgres/350-integrations/100-netlify.mdx +++ b/content/250-postgres/350-integrations/100-netlify.mdx @@ -120,7 +120,7 @@ In this section, you are going to add Prisma Postgres to the starter project _on ```terminal npm install prisma --save-dev ``` -1. Initialize Prisma ORM to create Prisma schema and `.env` file: +1. Initialize Prisma ORM to create Prisma schema, config and `.env` file: ```terminal npx prisma init ``` diff --git a/content/600-about/30-docs-components/01-mdx-examples.mdx b/content/600-about/30-docs-components/01-mdx-examples.mdx index 4496424195..2a18475965 100644 --- a/content/600-about/30-docs-components/01-mdx-examples.mdx +++ b/content/600-about/30-docs-components/01-mdx-examples.mdx @@ -341,17 +341,25 @@ yarn run v1.22.0 warning package.json: No license field $ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init -βœ” Your Prisma schema was created at prisma/schema.prisma. - You can now open it in your favorite editor. +Initialized Prisma in your project -Next steps: -1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started. -2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql or sqlite. -3. Run `prisma db pull` to introspect your database schema and update the Prisma schema data models accordingly. -4. Run `prisma generate` to install Prisma Client. You can then start querying your database. + prisma/ + schema.prisma + prisma.config.ts -More information in our documentation: -https://pris.ly/d/getting-started +Next, choose how you want to set up your database: + +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in `prisma.config.ts` + 2. Run `npx prisma db pull` to introspect your database. + +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + + Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema. + +Learn more: https://pris.ly/getting-started ``` @@ -379,17 +387,25 @@ yarn run v1.22.0 warning package.json: No license field $ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init -βœ” Your Prisma schema was created at prisma/schema.prisma. - You can now open it in your favorite editor. +Initialized Prisma in your project + + prisma/ + schema.prisma + prisma.config.ts -Next steps: -1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started. -2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql or sqlite. -3. Run `prisma db pull` to introspect your database schema and update the Prisma schema data models accordingly. -4. Run `prisma generate` to install Prisma Client. You can then start querying your database. +Next, choose how you want to set up your database: -More information in our documentation: -https://pris.ly/d/getting-started +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in `prisma.config.ts` + 2. Run `npx prisma db pull` to introspect your database. + +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + + Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema. + +Learn more: https://pris.ly/getting-started ``` @@ -417,17 +433,26 @@ yarn run v1.22.0 warning package.json: No license field $ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init -βœ” Your Prisma schema was created at prisma/schema.prisma. - You can now open it in your favorite editor. -Next steps: -1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started. -2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql or sqlite. -3. Run `prisma db pull` to introspect your database schema and update the Prisma schema data models accordingly. -4. Run `prisma generate` to install Prisma Client. You can then start querying your database. +Initialized Prisma in your project + + prisma/ + schema.prisma + prisma.config.ts -More information in our documentation: -https://pris.ly/d/getting-started +Next, choose how you want to set up your database: + +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in `prisma.config.ts` + 2. Run `npx prisma db pull` to introspect your database. + +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) + + Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema. + +Learn more: https://pris.ly/getting-started ``` @@ -455,17 +480,25 @@ yarn run v1.22.0 warning package.json: No license field $ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init -βœ” Your Prisma schema was created at prisma/schema.prisma. - You can now open it in your favorite editor. +Initialized Prisma in your project + + prisma/ + schema.prisma + prisma.config.ts + +Next, choose how you want to set up your database: + +CONNECT EXISTING DATABASE: + 1. Configure your DATABASE_URL in `prisma.config.ts` + 2. Run `npx prisma db pull` to introspect your database. + +CREATE NEW DATABASE: + Local: npx prisma dev (runs Postgres locally in your terminal) + Cloud: npx create-db (creates a free Prisma Postgres database) -Next steps: -1. Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started. -2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql or sqlite. -3. Run `prisma db pull` to introspect your database schema and update the Prisma schema data models accordingly. -4. Run `prisma generate` to install Prisma Client. You can then start querying your database. + Then, define your models in `prisma/schema.prisma` and run `npx prisma migrate dev` to apply your schema. -More information in our documentation: -https://pris.ly/d/getting-started +Learn more: https://pris.ly/getting-started ``` From 97eba07bd798d416523daa946185802996ed53e3 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:57:54 +0600 Subject: [PATCH 06/10] feat: update prisma cli docs --- .../200-prisma-cli-reference.mdx | 194 +++++++++++++++--- 1 file changed, 162 insertions(+), 32 deletions(-) diff --git a/content/200-orm/500-reference/200-prisma-cli-reference.mdx b/content/200-orm/500-reference/200-prisma-cli-reference.mdx index 20fb5b52de..2b42df9c33 100644 --- a/content/200-orm/500-reference/200-prisma-cli-reference.mdx +++ b/content/200-orm/500-reference/200-prisma-cli-reference.mdx @@ -291,11 +291,10 @@ prisma init --preview-feature metrics ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" previewFeatures = ["metrics"] } ``` @@ -319,11 +318,10 @@ prisma init --preview-feature view --preview-feature metrics ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" previewFeatures = ["views", "metrics"] } ``` @@ -343,16 +341,35 @@ An initial `schema.prisma` file to define your schema in: // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` +**`prisma.config.ts`** + +A TypeScript configuration file for Prisma that defines your datasource URL and other settings: + +```typescript +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +See the [Prisma Config reference](/orm/reference/prisma-config-reference) for more details. + **`.env`** A file to define environment variables for your project: @@ -364,7 +381,7 @@ A file to define environment variables for your project: # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. # See the documentation for all the connection string options: https://pris.ly/d/connection-strings -DATABASE_URL="file:./dev.db" +DATABASE_URL="postgresql://user:password@localhost:5432/mydb" ``` **`.gitignore`** @@ -399,14 +416,32 @@ A minimal `schema.prisma` file to define your schema in: datasource db { provider = "mysql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "../generated/prisma" } ``` +**`prisma.config.ts`** + +A TypeScript configuration file for Prisma with the custom URL: + +```typescript +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + **`.env`** A file to define environment variables for your project: @@ -426,7 +461,7 @@ DATABASE_URL="mysql://user:password@localhost:3306/mydb" The `generate` command generates assets like Prisma Client based on the [`generator`](/orm/prisma-schema/overview/generators) and [`data model`](/orm/prisma-schema/data-model/models) blocks defined in your `prisma/schema.prisma` file. -The `generate` command is most often used to generate Prisma Client with the `prisma-client-js` generator. This does three things: +The `generate` command is most often used to generate Prisma Client with the `prisma-client` generator. This does three things: 1. Searches the current directory and parent directories to find the applicable `npm` project. It will create a `package.json` file in the current directory if it cannot find one. 2. Installs the `@prisma/client` into the `npm` project if it is not already present. @@ -434,11 +469,12 @@ The `generate` command is most often used to generate Prisma Client with the `pr #### Prerequisites -To use the `generate` command, you must add a generator definition in your `schema.prisma` file. The `prisma-client-js` generator, used to generate Prisma Client, can be added by including the following in your `schema.prisma` file: +To use the `generate` command, you must add a generator definition in your `schema.prisma` file. The `prisma-client` generator, used to generate Prisma Client, can be added by including the following in your `schema.prisma` file: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "../generated/prisma" } ``` @@ -905,17 +941,37 @@ Introspection with the `db pull` command on the [MongoDB connector](/orm/overvie #### Prerequisites -Before using the `db pull` command, you must define a valid [`datasource`](/orm/prisma-schema/overview/data-sources) within your `schema.prisma` file. +Before using the `db pull` command, you must configure your database connection in your `prisma.config.ts` file. -For example, the following `datasource` defines a SQLite database file within the current directory: +For example: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client" + output = "../generated/prisma" +} -```prisma datasource db { provider = "sqlite" - url = "file:my-database.db" } ``` +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + #### Options | Option | Required | Description | Default | @@ -1048,17 +1104,35 @@ See also: #### Prerequisites -Before using theΒ `db push`Β command, you must define a validΒ [datasource](/orm/prisma-schema/overview/data-sources)Β within yourΒ `schema.prisma`Β file. +Before using the `db push` command, you must configure your database connection in your `prisma.config.ts` file. -For example, the followingΒ `datasource`Β defines a SQLite database file within the current directory: +For example: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client" + output = "../generated/prisma" +} -```prisma datasource db { provider = "sqlite" - url = "file:my-database.db" } ``` +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + #### Options | Options | Required | Description | @@ -1142,17 +1216,37 @@ See also: #### Prerequisites -Before using the `db execute` command, if you do not use the `--url` option you must define a valid [`datasource`](/orm/prisma-schema/overview/data-sources) within your `schema.prisma` file. +Before using the `db execute` command, if you do not use the `--url` option you must configure your database connection in your `prisma.config.ts` file. -For example, the following `datasource` defines a SQLite database file within the current directory: +For example: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client" + output = "../generated/prisma" +} -```prisma datasource db { provider = "sqlite" - url = "file:my-database.db" } ``` +This how your `prisma.config.ts` file should look like: + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + #### Options One of the following data source inputs is required: @@ -1490,17 +1584,35 @@ See also: #### Prerequisites -Before using the `migrate diff` command, if you are using the `--from-schema-datasource` or `--to-schema-datasource` you must define a valid [`datasource`](/orm/prisma-schema/overview/data-sources) within your `schema.prisma` file. +Before using the `migrate diff` command, if you are using the `--from-schema-datasource` or `--to-schema-datasource` you must configure your database connection in your `prisma.config.ts` file. -For example, the following `datasource` defines a SQLite database file within the current directory: +For example: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client" + output = "../generated/prisma" +} -```prisma datasource db { provider = "sqlite" - url = "file:my-database.db" } ``` +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + #### Options One of the following `--from-...` options is required: @@ -1597,17 +1709,35 @@ The `studio` command allows you to interact with and manage your data interactiv #### Prerequisites -Before using the `studio` command, you must define a valid [`datasource`](/orm/prisma-schema/overview/data-sources) within your `schema.prisma` file. +Before using the `studio` command, you must configure your database connection in your `prisma.config.ts` file. + +For example: -For example, the following `datasource` defines a SQLite database file within the current directory: +```prisma file=schema.prisma +generator client { + provider = "prisma-client" + output = "../generated/prisma" +} -```prisma datasource db { provider = "sqlite" - url = "file:my-database.db" } ``` +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + #### Options The `studio` command recognizes the following options: From c1c8a27435fbe759edfe31fe005f8e7263accf91 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:25:55 +0600 Subject: [PATCH 07/10] fix: clarify the usage of prisma init better --- .../100-quickstart/100-prisma-postgres.mdx | 3 +- .../100-quickstart/200-sqlite.mdx | 10 ++-- .../100-quickstart/300-postgresql.mdx | 3 +- .../100-quickstart/500-sql-server.mdx | 3 +- .../100-quickstart/700-cockroachdb.mdx | 3 +- .../100-prisma-postgres.mdx | 2 +- .../200-sqlite.mdx | 2 +- .../300-postgresql.mdx | 2 +- .../500-sql-server.mdx | 2 +- .../700-cockroachdb.mdx | 2 +- .../500-databases/200-database-drivers.mdx | 47 ++++++++------- .../500-databases/300-postgresql.mdx | 27 ++++++--- .../050-overview/500-databases/400-mysql.mdx | 29 +++++++--- .../050-overview/500-databases/500-sqlite.mdx | 58 +++++++++++-------- .../500-databases/800-sql-server/index.mdx | 23 ++++++-- .../500-databases/840-cockroachdb.mdx | 20 +++++-- .../500-databases/850-planetscale.mdx | 17 +++++- 17 files changed, 165 insertions(+), 88 deletions(-) diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx index c73c259d73..e9af0bccd9 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx @@ -26,7 +26,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Install the packages needed for this quickstart: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -35,6 +35,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx index b4dcb6abf4..63b0e1b9de 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx @@ -28,7 +28,7 @@ In this guide, you will learn how to set up a new TypeScript project from scratc Install the packages needed for this quickstart: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/better-sqlite3 --save-dev npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv ``` @@ -37,6 +37,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-better-sqlite3`** - The SQLite driver adapter that connects Prisma Client to your database +- **`@types/better-sqlite3`** - TypeScript type definitions for better-sqlite3 - **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support @@ -94,16 +95,13 @@ import { defineConfig, env } from 'prisma/config' export default defineConfig({ schema: 'prisma/schema.prisma', - migrations: { - path: 'prisma/migrations', - }, datasource: { url: env('DATABASE_URL'), }, }) ``` -Add `dotenv` to `prisma.config.ts` so that Prisma can load environment variables from your `.env` file: +Add `dotenv` and migrations configuration to `prisma.config.ts`: ```typescript file=prisma.config.ts // add-start @@ -113,9 +111,11 @@ import { defineConfig, env } from 'prisma/config' export default defineConfig({ schema: 'prisma/schema.prisma', + // add-start migrations: { path: 'prisma/migrations', }, + // add-end datasource: { url: env('DATABASE_URL'), }, diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx index 53f3352521..a3f1c5f1e8 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx @@ -37,7 +37,7 @@ If you don't already have a PostgreSQL database, follow the quickstart to set up Install the packages needed for this quickstart: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -46,6 +46,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/500-sql-server.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/500-sql-server.mdx index f78be99bca..7bf7e8c667 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/500-sql-server.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/500-sql-server.mdx @@ -33,7 +33,7 @@ You also need: Install the packages needed for this quickstart: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/mssql --save-dev npm install @prisma/client @prisma/adapter-mssql dotenv ``` @@ -42,6 +42,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-mssql`** - The SQL Server driver adapter that connects Prisma Client to your database +- **`@types/mssql`** - TypeScript type definitions for mssql - **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx index 8768122e43..ac02ca0107 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx @@ -31,7 +31,7 @@ You also need: Install the packages needed for this quickstart: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` @@ -40,6 +40,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible) +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 3. Configure ESM support diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx index e6585e83b8..5365922db8 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx @@ -21,7 +21,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Navigate to your existing project directory and install the required dependencies: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx index e9d5d66134..2400869b03 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx @@ -21,7 +21,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Navigate to your existing project directory and install the required dependencies: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/better-sqlite3 --save-dev npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv ``` diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx index 46deacf6c4..0c58393551 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx @@ -21,7 +21,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Navigate to your existing project directory and install the required dependencies: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx index ca420d5d2b..4c207be56e 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx @@ -21,7 +21,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Navigate to your existing project directory and install the required dependencies: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/mssql --save-dev npm install @prisma/client @prisma/adapter-mssql dotenv ``` diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx index 8e6215d96a..a553644a00 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx @@ -21,7 +21,7 @@ import NextSteps from '../../_components/_next-steps.mdx' Navigate to your existing project directory and install the required dependencies: ```terminal -npm install prisma @types/node --save-dev +npm install prisma @types/node @types/pg --save-dev npm install @prisma/client @prisma/adapter-pg dotenv ``` diff --git a/content/200-orm/050-overview/500-databases/200-database-drivers.mdx b/content/200-orm/050-overview/500-databases/200-database-drivers.mdx index 323f9ca92c..169970c7e8 100644 --- a/content/200-orm/050-overview/500-databases/200-database-drivers.mdx +++ b/content/200-orm/050-overview/500-databases/200-database-drivers.mdx @@ -12,19 +12,18 @@ One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood :::note -As of [v6.15.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without Rust engines in production applications. Learn more [here](/orm/prisma-client/setup-and-configuration/no-rust-engine). +As of Prisma ORM 7, the query compiler (client engine) is the default, which means Prisma Client is generated without a Rust-based query engine binary. This provides better performance and developer experience. Learn more [here](/orm/prisma-client/setup-and-configuration/no-rust-engine). -**When enabled, your Prisma Client will be generated without a Rust-based query engine binary**: +In Prisma ORM 7, the default generator configuration is: ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" - output = "../src/generated/prisma" - engineType = "client" // no Rust engine + provider = "prisma-client" + output = "../generated/prisma" } ``` -Note that [driver adapters](/orm/overview/databases/database-drivers#driver-adapters) are required if you want to use Prisma ORM without Rust engines. +Note that [driver adapters](/orm/overview/databases/database-drivers#driver-adapters) are required when using the query compiler. You can [read about the performance and DX improvements](https://www.prisma.io/blog/prisma-orm-without-rust-latest-performance-benchmarks) of this change on our blog. @@ -120,7 +119,7 @@ As of the 6.6.0 release, you instantiate the driver adapter _directly_ with the ```typescript import { PrismaLibSQL } from '@prisma/adapter-libsql' -import { PrismaClient } from '../prisma/prisma-client' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaLibSQL({ url: env.LIBSQL_DATABASE_URL, @@ -130,17 +129,18 @@ const adapter = new PrismaLibSQL({ const prisma = new PrismaClient({ adapter }) ``` -### Driver adapters don't read the connection string from the Prisma schema +### Driver adapters and database connection configuration -When using Prisma ORM's built-in drivers, the connection string is read from the `url` field of the `datasource` block in your Prisma schema. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference). However, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. -On the other hand, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter: +Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter: ```ts -import { PrismaClient } from '@prisma/client' +import 'dotenv/config' +import { PrismaClient } from '../generated/prisma/client' import { PrismaPg } from '@prisma/adapter-pg' -const adapter = new PrismaPg({ connectionString: env.DATABASE_URL }) +const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` @@ -148,34 +148,33 @@ See the docs for the driver adapter you're using for concrete setup instructions ### Driver adapters and custom output paths -Since Prisma 5.9.0, when using the driver adapters Preview feature along with a [custom output path for Prisma Client](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path), you cannot reference Prisma Client using a relative path. +In Prisma ORM 7, the recommended approach is to use a custom output path for Prisma Client. The default output path is `../generated/prisma`. -Let's assume you had `output` in your Prisma schema set to `../src/generated/client`: +Let's assume you have `output` in your Prisma schema set to `../generated/prisma`: ```prisma generator client { - provider = "prisma-client-js" - output = "../src/generated/client" + provider = "prisma-client" + output = "../generated/prisma" } ``` -What you should _not_ do is reference that path relatively: +You can reference Prisma Client using a relative path from your application code: -```ts no-copy -// what not to do! -import { PrismaClient } from './src/generated/client' +```ts +import { PrismaClient } from '../generated/prisma/client' const client = new PrismaClient() ``` -Instead, you will need to use a linked dependency. +Alternatively, you can use a linked dependency for cleaner imports. ```terminal -npm add db@./src/generated/client +npm add db@./generated/prisma ``` @@ -183,7 +182,7 @@ npm add db@./src/generated/client ```terminal -pnpm add db@link:./src/generated/client +pnpm add db@link:./generated/prisma ``` @@ -191,7 +190,7 @@ pnpm add db@link:./src/generated/client ```terminal -yarn add db@link:./src/generated/client +yarn add db@link:./generated/prisma ``` diff --git a/content/200-orm/050-overview/500-databases/300-postgresql.mdx b/content/200-orm/050-overview/500-databases/300-postgresql.mdx index fc4144ba28..563f9e688e 100644 --- a/content/200-orm/050-overview/500-databases/300-postgresql.mdx +++ b/content/200-orm/050-overview/500-databases/300-postgresql.mdx @@ -25,14 +25,26 @@ To connect to a PostgreSQL database server, you need to configure a [`datasource ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` -The fields passed to the `datasource` block are: +The `datasource` block specifies the `postgresql` data source connector. -- `provider`: Specifies the `postgresql` data source connector. -- `url`: Specifies the [connection URL](#connection-url) for the PostgreSQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +This configuration uses an [environment variable](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the database connection URL. ## Using the `node-postgres` driver @@ -55,13 +67,14 @@ npm install @prisma/adapter-pg Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: ```ts +import 'dotenv/config' import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' const connectionString = `${process.env.DATABASE_URL}` -const adapter = new PrismaPg({ connectionString }); -const prisma = new PrismaClient({ adapter }); +const adapter = new PrismaPg({ connectionString }) +const prisma = new PrismaClient({ adapter }) ``` Notice that this code requires the `DATABASE_URL` environment variable to be set to your PostgreSQL connection string. You can learn more about the connection string below. diff --git a/content/200-orm/050-overview/500-databases/400-mysql.mdx b/content/200-orm/050-overview/500-databases/400-mysql.mdx index d9b7033275..0b80fa0087 100644 --- a/content/200-orm/050-overview/500-databases/400-mysql.mdx +++ b/content/200-orm/050-overview/500-databases/400-mysql.mdx @@ -16,14 +16,26 @@ To connect to a MySQL database server, you need to configure a [`datasource`](/o ```prisma file=schema.prisma showLineNumbers datasource db { provider = "mysql" - url = env("DATABASE_URL") } ``` -The fields passed to the `datasource` block are: +The `datasource` block specifies the `mysql` data source connector, which is used for both MySQL and MariaDB. -- `provider`: Specifies the `mysql` data source connector, which is used both for MySQL and MariaDB. -- `url`: Specifies the [connection URL](#connection-url) for the MySQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +This configuration uses an [environment variable](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the database connection URL. ## Using the `mariadb` driver @@ -46,15 +58,16 @@ npm install @prisma/adapter-mariadb Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: ```ts -import { PrismaMariaDb } from '@prisma/adapter-mariadb'; -import { PrismaClient } from './generated/prisma'; +import 'dotenv/config' +import { PrismaMariaDb } from '@prisma/adapter-mariadb' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaMariaDb({ host: "localhost", port: 3306, connectionLimit: 5 -}); -const prisma = new PrismaClient({ adapter }); +}) +const prisma = new PrismaClient({ adapter }) ``` ## Connection details diff --git a/content/200-orm/050-overview/500-databases/500-sqlite.mdx b/content/200-orm/050-overview/500-databases/500-sqlite.mdx index db904f7aa8..7f4aec05df 100644 --- a/content/200-orm/050-overview/500-databases/500-sqlite.mdx +++ b/content/200-orm/050-overview/500-databases/500-sqlite.mdx @@ -16,14 +16,25 @@ To connect to a SQLite database file, you need to configure a [`datasource`](/or ```prisma file=schema.prisma datasource db { provider = "sqlite" - url = "file:./dev.db" } ``` -The fields passed to the `datasource` block are: +The `datasource` block specifies the `sqlite` data source connector. -- `provider`: Specifies the `sqlite` data source connector. -- `url`: Specifies the [connection URL](/orm/reference/connection-urls) for the SQLite database. The connection URL always starts with the prefix `file:` and then contains a file path pointing to the SQLite database file. In this case, the file is located in the same directory and called `dev.db`. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: 'file:./dev.db', + }, +}) +``` + +The connection URL always starts with the prefix `file:` and then contains a file path pointing to the SQLite database file. In this example, the file is located in the same directory and called `dev.db`. ## Using the `better-sqlite3` driver @@ -46,13 +57,13 @@ npm install @prisma/adapter-better-sqlite3 Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: ```ts -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; -import { PrismaClient } from './generated/prisma'; +import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaBetterSQLite3({ url: "file:./prisma/dev.db" -}); -const prisma = new PrismaClient({ adapter }); +}) +const prisma = new PrismaClient({ adapter }) ``` ### 3. Configure timestamp format for backward compatibility @@ -64,15 +75,15 @@ By default, driver adapters store `DateTime` values as **ISO 8601 strings**, whi However, if you need **100% backward compatibility** with Prisma ORM's native SQLite driver (for example, when migrating an existing database), you should use the `unixepoch-ms` format, which stores timestamps as the number of milliseconds since the Unix epoch: ```ts -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; -import { PrismaClient } from './generated/prisma'; +import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaBetterSQLite3({ url: "file:./prisma/dev.db" }, { timestampFormat: 'unixepoch-ms' -}); -const prisma = new PrismaClient({ adapter }); +}) +const prisma = new PrismaClient({ adapter }) ``` :::info @@ -138,29 +149,26 @@ try migrating the 'int' column type to BIGINT ### Connection URL -The connection URL of a SQLite connector points to a file on your file system. For example, the following two paths are equivalent because the `.db` is in the same directory: +The connection URL of a SQLite connector points to a file on your file system and is configured in `prisma.config.ts`. For example, the following two paths are equivalent because the `.db` is in the same directory: -```prisma file=schema.prisma -datasource db { - provider = "sqlite" - url = "file:./dev.db" +```typescript file=prisma.config.ts +datasource: { + url: 'file:./dev.db', } ``` is the same as: -```prisma file=schema.prisma -datasource db { - provider = "sqlite" - url = "file:dev.db" +```typescript file=prisma.config.ts +datasource: { + url: 'file:dev.db', } ``` You can also target files from the root or any other place in your file system: -```prisma file=schema.prisma -datasource db { - provider = "sqlite" - url = "file:/Users/janedoe/dev.db" +```typescript file=prisma.config.ts +datasource: { + url: 'file:/Users/janedoe/dev.db', } ``` diff --git a/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx b/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx index b118b92b32..a1b1cd989b 100644 --- a/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx +++ b/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx @@ -15,14 +15,26 @@ To connect to a Microsoft SQL Server database, you need to configure a [`datasou ```prisma file=schema.prisma showLineNumbers datasource db { provider = "sqlserver" - url = env("DATABASE_URL") } ``` -The fields passed to the `datasource` block are: +The `datasource` block specifies the `sqlserver` data source connector. -- `provider`: Specifies the `sqlserver` data source connector. -- `url`: Specifies the [connection URL](#connection-details) for the Microsoft SQL Server database. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +This configuration uses an [environment variable](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the database connection URL. ## Using the `node-mssql` driver @@ -46,8 +58,9 @@ npm install @prisma/adapter-mssql Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: ```ts +import 'dotenv/config' import { PrismaMssql } from '@prisma/adapter-mssql' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' const config = { server: 'localhost', diff --git a/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx b/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx index ca6984dd09..03aa4a0d6e 100644 --- a/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx +++ b/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx @@ -99,14 +99,26 @@ To connect to a CockroachDB database server, you need to configure a [`datasourc ```prisma file=schema.prisma showLineNumbers datasource db { provider = "cockroachdb" - url = env("DATABASE_URL") } ``` -The fields passed to the `datasource` block are: +The `datasource` block specifies the `cockroachdb` data source connector. -- `provider`: Specifies the `cockroachdb` data source connector. -- `url`: Specifies the [connection URL](#connection-details) for the CockroachDB database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +This configuration uses an [environment variable](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the database connection URL. diff --git a/content/200-orm/050-overview/500-databases/850-planetscale.mdx b/content/200-orm/050-overview/500-databases/850-planetscale.mdx index d325915dc1..fdd968664d 100644 --- a/content/200-orm/050-overview/500-databases/850-planetscale.mdx +++ b/content/200-orm/050-overview/500-databases/850-planetscale.mdx @@ -70,11 +70,26 @@ To enable emulation of relations in Prisma Client, set the `relationMode` field ```prisma file=schema.prisma datasource db { provider = "mysql" - url = env("DATABASE_URL") relationMode = "prisma" } ``` +In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference): + +```typescript file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' +import 'dotenv/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + +This configuration uses an environment variable to provide the database connection URL. Learn more in the [Prisma Config reference](/orm/reference/prisma-config-reference). + The ability to set the relation mode was introduced as part of the `referentialIntegrity` preview feature in Prisma ORM version 3.1.1, and is generally available in Prisma ORM versions 4.8.0 and later.

The `relationMode` field was renamed in Prisma ORM version 4.5.0, and was previously named `referentialIntegrity`. From e4cf39fb4702ede1e6655cd05d906e8bcbd57794 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:37:08 +0600 Subject: [PATCH 08/10] fix: add type defs --- .../200-add-to-existing-project/100-prisma-postgres.mdx | 1 + .../02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx | 1 + .../02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx | 1 + .../02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx | 1 + .../200-add-to-existing-project/700-cockroachdb.mdx | 1 + 5 files changed, 5 insertions(+) diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx index c0b0d54180..58f0039118 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 2. Initialize Prisma ORM diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx index 504c943e80..4829c9be51 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-better-sqlite3`** - The SQLite driver adapter that connects Prisma Client to your database +- **`@types/better-sqlite3`** - TypeScript type definitions for better-sqlite3 - **`dotenv`** - Loads environment variables from your `.env` file ## 2. Initialize Prisma ORM diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx index 090de292c9..9b6cdca3fe 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 2. Initialize Prisma ORM diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx index 3d1bd032bc..31dfe9f393 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/500-sql-server.mdx @@ -30,6 +30,7 @@ Here's what each package does: - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-mssql`** - The SQL Server driver adapter that connects Prisma Client to your database - **`dotenv`** - Loads environment variables from your `.env` file +- **`@types/mssql`** - TypeScript type definitions for mssql ## 2. Initialize Prisma ORM diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx index 25e4df0e93..0a67705e18 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible) +- **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file ## 2. Initialize Prisma ORM From 17b67d79b51f1e8329e9b22efd50f6f4e5e46f26 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 18:45:40 +0600 Subject: [PATCH 09/10] feat: add pg as a dependency --- .../02-prisma-orm/100-quickstart/100-prisma-postgres.mdx | 3 ++- .../02-prisma-orm/100-quickstart/300-postgresql.mdx | 3 ++- .../02-prisma-orm/100-quickstart/700-cockroachdb.mdx | 3 ++- .../200-add-to-existing-project/100-prisma-postgres.mdx | 3 ++- .../200-add-to-existing-project/300-postgresql.mdx | 3 ++- .../200-add-to-existing-project/700-cockroachdb.mdx | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx index 008b5ec160..a5cb227c42 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/100-prisma-postgres.mdx @@ -26,7 +26,7 @@ Install the packages needed for this quickstart: ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -34,6 +34,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx index 5e892907b0..bb7b117053 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/300-postgresql.mdx @@ -37,7 +37,7 @@ Install the packages needed for this quickstart: ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -45,6 +45,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx index 4532fd6764..601a6a775b 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/700-cockroachdb.mdx @@ -31,7 +31,7 @@ Install the packages needed for this quickstart: ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -39,6 +39,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible) +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx index 58f0039118..f415afdace 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/100-prisma-postgres.mdx @@ -21,7 +21,7 @@ Navigate to your existing project directory and install the required dependencie ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx index 9b6cdca3fe..025304d8ff 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/300-postgresql.mdx @@ -21,7 +21,7 @@ Navigate to your existing project directory and install the required dependencie ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx index 0a67705e18..5b878d723c 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/700-cockroachdb.mdx @@ -21,7 +21,7 @@ Navigate to your existing project directory and install the required dependencie ```terminal npm install prisma @types/node @types/pg --save-dev -npm install @prisma/client @prisma/adapter-pg dotenv +npm install @prisma/client @prisma/adapter-pg pg dotenv ``` Here's what each package does: @@ -29,6 +29,7 @@ Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate` - **`@prisma/client`** - The Prisma Client library for querying your database - **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible) +- **`pg`** - The node-postgres database driver - **`@types/pg`** - TypeScript type definitions for node-postgres - **`dotenv`** - Loads environment variables from your `.env` file From 96b202e59f95fc6ed4af86a01f919cba768cb4a1 Mon Sep 17 00:00:00 2001 From: Ankur Datta <64993082+ankur-arch@users.noreply.github.com> Date: Mon, 17 Nov 2025 19:22:21 +0600 Subject: [PATCH 10/10] fix: broken internal link --- .../200-prisma-client/100-queries/037-relation-queries.mdx | 6 +++--- .../200-orm/500-reference/050-prisma-client-reference.mdx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx b/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx index daffbf41a1..ee1d12b671 100644 --- a/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx +++ b/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx @@ -530,7 +530,7 @@ const result = await prisma.user.create({ There are two ways to create or update a single record and multiple related records - for example, a user with multiple posts: -- Use a nested [`create`](/orm/reference/prisma-client-reference#create-1) query +- Use a nested [`create`](/orm/reference/prisma-client-reference#create) query - Use a nested [`createMany`](/orm/reference/prisma-client-reference#createmany-1) query In most cases, a nested `create` will be preferable unless the [`skipDuplicates` query option](/orm/reference/prisma-client-reference#nested-createmany-options) is required. Here's a quick table describing the differences between the two options: @@ -544,7 +544,7 @@ In most cases, a nested `create` will be preferable unless the [`skipDuplicates` #### Using nested `create` -The following query uses nested [`create`](/orm/reference/prisma-client-reference#create-1) to create: +The following query uses nested [`create`](/orm/reference/prisma-client-reference#create) to create: - One user - Two posts @@ -640,7 +640,7 @@ Here's a visual representation of how a nested create operation can write to sev #### Using nested `createMany` -The following query uses a nested [`createMany`](/orm/reference/prisma-client-reference#create-1) to create: +The following query uses a nested [`createMany`](/orm/reference/prisma-client-reference#create) to create: - One user - Two posts diff --git a/content/200-orm/500-reference/050-prisma-client-reference.mdx b/content/200-orm/500-reference/050-prisma-client-reference.mdx index f92eadde2b..8ea2c2473f 100644 --- a/content/200-orm/500-reference/050-prisma-client-reference.mdx +++ b/content/200-orm/500-reference/050-prisma-client-reference.mdx @@ -825,7 +825,7 @@ const user = await prisma.user.findMany({ #### Remarks -- You can also perform a nested [`create`](#create-1) - for example, add a `User` and two `Post` records at the same time. +- You can also perform a nested [`create`](#create) - for example, add a `User` and two `Post` records at the same time. #### Examples