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..c28b1f4514 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 @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and Prisma Postgres' sidebar_label: 'Prisma Postgres' 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' 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..f04dc1ca00 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 @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and SQLite' sidebar_label: 'SQLite' metaTitle: 'Quickstart: Prisma ORM with SQLite (5 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to SQLite and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '5 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..2d31c50999 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 @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and PostgreSQL' sidebar_label: 'PostgreSQL' metaTitle: 'Quickstart: Prisma ORM with PostgreSQL (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to PostgreSQL and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/400-mysql.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/400-mysql.mdx index 8edc3e72df..6a02d9858b 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/400-mysql.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/400-mysql.mdx @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and MySQL' sidebar_label: 'MySQL' metaTitle: 'Quickstart: Prisma ORM with MySQL (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to MySQL and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..b7c23969ef 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 @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and SQL Server' sidebar_label: 'SQL Server' metaTitle: 'Quickstart: Prisma ORM with SQL Server (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to SQL Server and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/600-planetscale.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/600-planetscale.mdx index d6c4752fb5..f5836d6792 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/600-planetscale.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/600-planetscale.mdx @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and PlanetScale' sidebar_label: 'PlanetScale' metaTitle: 'Quickstart: Prisma ORM with PlanetScale MySQL (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to PlanetScale MySQL and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..f227598dc7 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 @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and CockroachDB' sidebar_label: 'CockroachDB' metaTitle: 'Quickstart: Prisma ORM with CockroachDB (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to CockroachDB and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/100-quickstart/800-mongodb.mdx b/content/100-getting-started/02-prisma-orm/100-quickstart/800-mongodb.mdx index a3594ba48e..13b0375a2e 100644 --- a/content/100-getting-started/02-prisma-orm/100-quickstart/800-mongodb.mdx +++ b/content/100-getting-started/02-prisma-orm/100-quickstart/800-mongodb.mdx @@ -3,7 +3,6 @@ title: 'Quickstart with Prisma ORM and MongoDB' sidebar_label: 'MongoDB' metaTitle: 'Quickstart: Prisma ORM with MongoDB (10 min)' metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to MongoDB and generating a Prisma Client for database access.' -sidebar_custom_props: { badge: '10 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..07b5149aaf 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 @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing Prisma Postgres project' sidebar_title: 'Prisma Postgres' metaTitle: 'How to add Prisma ORM to an existing project using Prisma Postgres (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with Prisma Postgres and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..9109da70fe 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 @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing SQLite project' sidebar_title: 'SQLite' metaTitle: 'How to add Prisma ORM to an existing project using SQLite (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with SQLite and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..4c9160e611 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 @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing PostgreSQL project' sidebar_title: 'PostgreSQL' metaTitle: 'How to add Prisma ORM to an existing project using PostgreSQL (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with PostgreSQL and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/400-mysql.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/400-mysql.mdx index 6830a8aa8c..ada30bc3ff 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/400-mysql.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/400-mysql.mdx @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing MySQL project' sidebar_title: 'MySQL' metaTitle: 'How to add Prisma ORM to an existing project using MySQL (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with MySQL and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..0ae3bd823d 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 @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing SQL Server project' sidebar_title: 'SQL Server' metaTitle: 'How to add Prisma ORM to an existing project using SQL Server (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with SQL Server and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/600-planetscale.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/600-planetscale.mdx index 66bf9be2f2..73a77b3044 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/600-planetscale.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/600-planetscale.mdx @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing PlanetScale project' sidebar_title: 'PlanetScale' metaTitle: 'How to add Prisma ORM to an existing project using PlanetScale MySQL (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with PlanetScale MySQL and learn database introspection and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' 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..7908afe4a6 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 @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing CockroachDB project' sidebar_title: 'CockroachDB' metaTitle: 'How to add Prisma ORM to an existing project using CockroachDB (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with CockroachDB and learn database introspection, baselining, and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.mdx' diff --git a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx index 7fc993a4c7..b0cf0e76b9 100644 --- a/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx +++ b/content/100-getting-started/02-prisma-orm/200-add-to-existing-project/800-mongodb.mdx @@ -3,7 +3,6 @@ title: 'Add Prisma ORM to an existing MongoDB project' sidebar_title: 'MongoDB' metaTitle: 'How to add Prisma ORM to an existing project using MongoDB (15 min)' metaDescription: 'Add Prisma ORM to an existing TypeScript project with MongoDB and learn database introspection and querying.' -sidebar_custom_props: { badge: '15 min' } --- import Prerequisites from '../../_components/_prerequisites.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 1b2b1ff247..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,107 +3,222 @@ 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 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). +## 1. Create a new project -## 1. Create a Prisma Postgres database +Create a new directory for your project and initialize it with npm: -Follow these steps to create your Prisma Postgres database: +```terminal +mkdir kysely-quickstart +cd kysely-quickstart +npm init -y +``` -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. +Install TypeScript and initialize it: -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**. +```terminal +npm install --save-dev typescript +npx tsc --init +``` -Once the green **CONNECTED** label appears, your database is ready to use! +## 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 + // ... + } + // ... +} +``` + +:::note -## 2. Get your direct connection string +The `strict: true` setting is **required** for Kysely's type safety to work correctly. -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. +In your `package.json`, set the `type` to `module`: + +```json +{ +// ... +// add-start +"type": "module" +// add-end +// ... +} +``` -## 3. Create a new project +## 3. Create a Prisma Postgres database -Create a new directory for your project and initialize it: +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 +``` + +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" +``` + +:::warning + +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. + +::: + +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 ``` -## 4. Configure Kysely with Prisma Postgres +**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 database connection file that uses your Prisma Postgres connection string: +Create a `src/types.ts` file to define your database schema types: +```typescript file=src/types.ts +import type { Generated } from "kysely"; -```typescript file=database.ts +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: - -```env file=.env -DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" -``` - -## 5. Use Kysely with Prisma Postgres +## 7. Run queries -Now you can use Kysely to query your Prisma Postgres database: +Create a `src/script.ts` file: -```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 +251,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) +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 c729d66565..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 @@ -2,192 +2,187 @@ 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.' -sidebar_custom_props: { badge: '10 min' } +metaDescription: 'Get started with Drizzle ORM and Prisma Postgres.' --- -[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). +## 1. Create a new project -## 1. Create a Prisma Postgres database +Create a new directory for your project and initialize it with npm: -Follow these steps to create your Prisma Postgres database: +```terminal +mkdir drizzle-quickstart +cd drizzle-quickstart +npm init -y +``` -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. +Install TypeScript and initialize it: -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**. +```terminal +npm install --save-dev typescript +npx tsc --init +``` -Once the green **CONNECTED** label appears, your database is ready to use! +In your `package.json`, set the `type` to `module`: -## 2. Get your direct connection string +```json file=package.json +{ + // ... + // add-start + "type": "module" + // add-end + // ... +} +``` -To connect to Prisma Postgres via direct TCP, you need to: +## 2. Create a Prisma Postgres database -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. +You can create a Prisma Postgres database using the `create-db` CLI tool. Follow these steps to create your Prisma Postgres database: -## 3. Create a new project +```terminal +npx create-db +``` -Create a new directory for your project and initialize it: +Then the CLI tool should output: ```terminal -mkdir drizzle-quickstart -cd drizzle-quickstart -npm init -y +┌ 🚀 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. +│ +└ ``` -## 4. Configure Drizzle ORM with Prisma Postgres +Create a `.env` file and add the connection string from the output: -Define your database schema using Drizzle's schema definition: +```env file=.env +DATABASE_URL="postgresql://hostname:password@db.prisma.io:5432/postgres?sslmode=require" +``` +:::warning -```typescript file=schema.ts -import { pgTable, serial, text, varchar, boolean, timestamp, integer } from 'drizzle-orm/pg-core' -import { relations } from 'drizzle-orm' +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. -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(), -}) +::: -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(), -}) +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. -// 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], - }), -})) -``` +:::note -Configure Drizzle Kit with your Prisma Postgres connection string: +To learn more about the `create-db` CLI tool, see the [create-db documentation](/postgres/introduction/npx-create-db). -```typescript file=drizzle.config.ts -import { defineConfig } from 'drizzle-kit' +::: -export default defineConfig({ - schema: './schema.ts', - out: './drizzle', - dialect: 'postgresql', - dbCredentials: { - url: process.env.DATABASE_URL!, - }, -}) -``` +## 3. Install dependencies -Create a `.env` file and add your Prisma Postgres connection string: +Install Drizzle ORM and the PostgreSQL driver: -```env file=.env -DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" +```terminal +npm install drizzle-orm pg dotenv +npm install --save-dev drizzle-kit @types/pg tsx ``` -Create a database connection file: +**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 + +## 4. Run a query + +Create a `src/script.ts` file: -```typescript file=db.ts +```typescript file=src/script.ts +import 'dotenv/config' import { drizzle } from 'drizzle-orm/node-postgres' import { Pool } from 'pg' -import * as schema from './schema' const pool = new Pool({ connectionString: process.env.DATABASE_URL, }) -export const db = drizzle({ client: pool, schema }) -``` - -## 5. Use Drizzle ORM with Prisma Postgres - -Generate and push your schema to the database: - -```terminal -npx drizzle-kit push -``` - -Now you can use Drizzle ORM to query your Prisma Postgres database: - -```typescript file=script.ts -import { db } from './db' -import { users, posts } from './schema' -import { eq } from 'drizzle-orm' +const db = drizzle({ client: pool }) 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, - }, - }) - - console.log('Users with posts:', JSON.stringify(usersWithPosts, null, 2)) + 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: + +```terminal +npx tsx src/script.ts +``` -Now that you have Drizzle ORM connected to Prisma Postgres, you can: +You should receive output similar to: -- **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 +```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 +``` -## More info +## 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) +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..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,183 +3,179 @@ 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 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. +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" +``` -## 4. Define your entities +:::warning -Create your TypeORM entities as usual. Here's an example with User and Post entities: +**Never commit `.env` files to version control.** Add `.env` to your `.gitignore` file to keep credentials secure. -```typescript file=entity/User.ts -import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from "typeorm" -import { Post } from "./Post" +::: -@Entity() -export class User { - @PrimaryGeneratedColumn() - id: number +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. - @Column({ unique: true }) - email: string +:::note - @Column({ nullable: true }) - name: string +To learn more about the `create-db` CLI tool, see the [create-db documentation](/postgres/introduction/npx-create-db). - @OneToMany(() => Post, (post) => post.author) - posts: Post[] -} -``` +::: -```typescript file=entity/Post.ts -import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm" -import { User } from "./User" +## 4. Configure database connection -@Entity() -export class Post { - @PrimaryGeneratedColumn() - id: number +Update the `src/data-source.ts` file to use your Prisma Postgres connection: - @Column() - title: string +```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" - @Column({ type: "text", nullable: true }) - content: string +// 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 '/' + } +} - @Column({ default: false }) - published: boolean +const connectionParams = parseConnectionString(process.env.DATABASE_URL!) +// add-end - @ManyToOne(() => User, (user) => user.posts) - author: User -} +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: [], +}) ``` -For more information on defining entities, see the [TypeORM Entities documentation](https://typeorm.io/docs/entity/entities). - -## 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/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..b5c9e63729 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -82,65 +82,41 @@ const sidebars: SidebarsConfig = { type: "doc", id: "getting-started/prisma-orm/quickstart/prisma-postgres", label: "Prisma Postgres", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/mysql", label: "MySQL", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/postgresql", label: "PostgreSQL", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/sqlite", label: "SQLite", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/sql-server", label: "SQL Server", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/planetscale", label: "PlanetScale", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/cockroachdb", label: "CockroachDB", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/quickstart/mongodb", label: "MongoDB", - customProps: { - badge: "5 Min", - }, }, ], }, @@ -162,65 +138,41 @@ const sidebars: SidebarsConfig = { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/prisma-postgres", label: "Prisma Postgres", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/mysql", label: "MySQL", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/postgresql", label: "PostgreSQL", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/sqlite", label: "SQLite", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/sql-server", label: "SQL Server", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/planetscale", label: "PlanetScale", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/cockroachdb", label: "CockroachDB", - customProps: { - badge: "5 Min", - }, }, { type: "doc", id: "getting-started/prisma-orm/add-to-existing-project/mongodb", label: "MongoDB", - customProps: { - badge: "5 Min", - }, }, ], }, @@ -254,33 +206,30 @@ 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", - }, + type: "category", + label: "Other tools", + collapsed: false, + collapsible: false, + className: "sidebar-item-normal-weight", + items: [ + { + type: "doc", + id: "getting-started/prisma-postgres/quickstart/kysely", + label: "Kysely", + }, + { + type: "doc", + id: "getting-started/prisma-postgres/quickstart/drizzle-orm", + label: "Drizzle ORM", + }, + { + type: "doc", + id: "getting-started/prisma-postgres/quickstart/typeorm", + label: "TypeORM", + }, + ], }, ], }, diff --git a/src/css/custom.css b/src/css/custom.css index 5ff447caf1..b301f3eb07 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -1827,4 +1827,12 @@ kbd.DocSearch-Commands-Key { .theme-doc-sidebar-item-category .menu__list .sidebar-item-normal-weight a.menu__link--active { font-weight: 600 !important; +} + +/* Make category labels with normal weight class have normal font weight and size */ +.theme-doc-sidebar-item-category.sidebar-item-normal-weight > .menu__list-item-collapsible > .menu__link, +.theme-doc-sidebar-item-category .sidebar-item-normal-weight > .menu__list-item-collapsible > .menu__link { + font-weight: normal !important; + font-size: 14px !important; + line-height: 1.25 !important; } \ No newline at end of file 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 ###