From c3be9a930e99342b3726ebebeaa3e6e1d0c819e3 Mon Sep 17 00:00:00 2001 From: ArthurGamby Date: Tue, 17 Feb 2026 10:54:17 +0100 Subject: [PATCH 1/3] fix(docs): require driver adapter in PrismaClient setup examples Co-Authored-By: Claude Opus 4.6 --- .../supported-databases/database-drivers.mdx | 8 +- .../setup-and-configuration/introduction.mdx | 93 ++++++++++++------- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/apps/docs/content/docs/orm/core-concepts/supported-databases/database-drivers.mdx b/apps/docs/content/docs/orm/core-concepts/supported-databases/database-drivers.mdx index bc3d393454..b2c0e4e73d 100644 --- a/apps/docs/content/docs/orm/core-concepts/supported-databases/database-drivers.mdx +++ b/apps/docs/content/docs/orm/core-concepts/supported-databases/database-drivers.mdx @@ -158,8 +158,10 @@ You can reference Prisma Client using a relative path from your application code ```ts import { PrismaClient } from "./generated/prisma/client"; +import { PrismaPg } from "@prisma/adapter-pg"; -const client = new PrismaClient(); +const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); +const client = new PrismaClient({ adapter }); ``` Alternatively, you can use a linked dependency for cleaner imports. @@ -178,8 +180,10 @@ Now, you should be able to reference your generated client using `db`! ```ts import { PrismaClient } from "db"; +import { PrismaPg } from "@prisma/adapter-pg"; -const client = new PrismaClient(); +const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); +const client = new PrismaClient({ adapter }); ``` ### Driver adapters and specific frameworks diff --git a/apps/docs/content/docs/orm/prisma-client/setup-and-configuration/introduction.mdx b/apps/docs/content/docs/orm/prisma-client/setup-and-configuration/introduction.mdx index d9a937418d..719a334b80 100644 --- a/apps/docs/content/docs/orm/prisma-client/setup-and-configuration/introduction.mdx +++ b/apps/docs/content/docs/orm/prisma-client/setup-and-configuration/introduction.mdx @@ -46,13 +46,29 @@ model User { ## Installation -[Install the Prisma CLI](/docs/orm/reference/prisma-cli-reference) and the Prisma Client library in your project: +[Install the Prisma CLI](/docs/orm/reference/prisma-cli-reference), the Prisma Client library, and the [driver adapter](/docs/orm/core-concepts/supported-databases/database-drivers) for your database: -```npm +```npm tab="PostgreSQL" +npm install prisma --save-dev +npm install @prisma/client @prisma/adapter-pg pg +``` + +```npm tab="MySQL / MariaDB" npm install prisma --save-dev -npm install @prisma/client +npm install @prisma/client @prisma/adapter-mariadb mariadb ``` +```npm tab="SQLite" +npm install prisma --save-dev +npm install @prisma/client @prisma/adapter-better-sqlite3 better-sqlite3 +``` + +:::note + +Prisma 7 requires a [driver adapter](/docs/orm/core-concepts/supported-databases/database-drivers) to connect to your database. Make sure your `package.json` includes `"type": "module"` for ESM support. See the [upgrade guide](/docs/guides/upgrade-prisma-orm/v7) for details. + +::: + ## Generate the Client API Prisma Client is based on the models in Prisma Schema. To provide the correct types, you need generate the client code: @@ -65,57 +81,70 @@ This will create a `generated` directory based on where you set the `output` to ## Importing Prisma Client -With the client generated, import the version for the given environment and create a new instance of it: +With the client generated, import it along with your [driver adapter](/docs/orm/core-concepts/supported-databases/database-drivers) and create a new instance: -```ts tab="Node" +```ts tab="PostgreSQL" import { PrismaClient } from "./path/to/generated/prisma"; +import { PrismaPg } from "@prisma/adapter-pg"; -export const prisma = new PrismaClient({}); -``` - -```ts tab="Edge" -import { PrismaClient } from "./path/to/generated/prisma/edge"; +const adapter = new PrismaPg({ + connectionString: process.env.DATABASE_URL!, +}); -export const prisma = new PrismaClient({}); +export const prisma = new PrismaClient({ adapter }); ``` -Your application should generally only create **one instance** of `PrismaClient`. How to achieve this depends on whether you are using Prisma ORM in a [long-running application](/docs/orm/prisma-client/setup-and-configuration/databases-connections#prismaclient-in-long-running-applications) or in a [serverless environment](/docs/orm/prisma-client/setup-and-configuration/databases-connections#prismaclient-in-serverless-environments) . +```ts tab="MySQL / MariaDB" +import { PrismaClient } from "./path/to/generated/prisma"; +import { PrismaMariaDb } from "@prisma/adapter-mariadb"; -Creating multiple instances of `PrismaClient` will create multiple connection pools and can hit the connection limit for your database. Too many connections may start to **slow down your database** and eventually lead to errors such as: +const adapter = new PrismaMariaDb({ + host: "localhost", + user: "root", + database: "mydb", +}); -```bash -Error in connector: Error querying the database: db error: FATAL: sorry, too many clients already - at PrismaClientFetcher.request +export const prisma = new PrismaClient({ adapter }); ``` -## Driver Adapters - -Depending on the database being used, an adapter is needed in order for Prisma Client to be able send the appropriate SQL queries: - -```ts tab="Prisma Postgre" +```ts tab="SQLite" import { PrismaClient } from "./path/to/generated/prisma"; -import { PrismaPg } from '@prisma/adapter-pg' +import { PrismaBetterSQLite3 } from "@prisma/adapter-better-sqlite3"; -const adapter = new PrismaPg({ - connectionString: process.env.DATABASE_URL!, -}) +const adapter = new PrismaBetterSQLite3({ + url: "file:./dev.db", +}); -export const prisma = new PrismaClient({adapter}); +export const prisma = new PrismaClient({ adapter }); ``` - -```ts tab="Prisma Postgres Serverless" +```ts tab="PostgreSQL (Edge)" import { PrismaClient } from "./path/to/generated/prisma/edge"; import { PrismaPostgresAdapter } from "@prisma/adapter-ppg"; -const adapter = new PrismaPg({ +const adapter = new PrismaPostgresAdapter({ connectionString: process.env.DATABASE_URL!, -}) +}); -export const prisma = new PrismaClient({adapter}); +export const prisma = new PrismaClient({ adapter }); ``` -Find out what [driver adapter](/docs/orm/core-concepts/supported-databases/database-drivers) is needed for your database +:::warning + +`PrismaClient` requires a driver adapter in Prisma 7. Calling `new PrismaClient()` without an `adapter` will result in an error. + +::: + +Find out what [driver adapter](/docs/orm/core-concepts/supported-databases/database-drivers) is needed for your database. + +Your application should generally only create **one instance** of `PrismaClient`. How to achieve this depends on whether you are using Prisma ORM in a [long-running application](/docs/orm/prisma-client/setup-and-configuration/databases-connections#prismaclient-in-long-running-applications) or in a [serverless environment](/docs/orm/prisma-client/setup-and-configuration/databases-connections#prismaclient-in-serverless-environments). + +Creating multiple instances of `PrismaClient` will create multiple connection pools and can hit the connection limit for your database. Too many connections may start to **slow down your database** and eventually lead to errors such as: + +```bash +Error in connector: Error querying the database: db error: FATAL: sorry, too many clients already + at PrismaClientFetcher.request +``` ## Use Prisma Client to send queries to your database From c85b08570da8f07aea13ca380a5d968f17a83655 Mon Sep 17 00:00:00 2001 From: ArthurGamby Date: Tue, 17 Feb 2026 11:14:12 +0100 Subject: [PATCH 2/3] docs: add Deno runtime guide --- .../content/docs/guides/runtimes/deno.mdx | 317 ++++++++++++++++++ .../content/docs/guides/runtimes/meta.json | 2 +- 2 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 apps/docs/content/docs/guides/runtimes/deno.mdx diff --git a/apps/docs/content/docs/guides/runtimes/deno.mdx b/apps/docs/content/docs/guides/runtimes/deno.mdx new file mode 100644 index 0000000000..846cb55568 --- /dev/null +++ b/apps/docs/content/docs/guides/runtimes/deno.mdx @@ -0,0 +1,317 @@ +--- +title: Deno +description: Learn how to use Prisma ORM in a Deno application with Prisma Postgres +url: /guides/runtimes/deno +--- + +## Introduction + +[Deno](https://deno.com) is a secure JavaScript and TypeScript runtime built on V8 with built-in TypeScript support, a permissions system, and web-standard APIs. In this guide, you will set up a Deno project with Prisma ORM and a Prisma Postgres database. You will create a simple HTTP server that reads from the database and returns the results. + +## Prerequisites + +- [Deno](https://docs.deno.com/runtime/#install-deno) v2.0 or later installed on your system +- A [Prisma Postgres database](/postgres) (created during setup) +- Basic knowledge of JavaScript/TypeScript +- [Deno extension for VS Code](https://docs.deno.com/runtime/reference/vscode/) (recommended) + +## 1. Setting up your Deno project + +First, create a directory for your project and navigate to it: + +```bash +mkdir deno-prisma +cd deno-prisma +``` + +Then, initialize a new Deno project: + +```bash +deno init +``` + +This creates a basic Deno project with a `deno.json` configuration file and a `main.ts` file. + +### 1.1. Configure Deno for Prisma + +Update the `deno.json` file with the following configuration to set up Node.js compatibility, import maps, and Prisma-related task scripts: + +```json title="deno.json" +{ + "nodeModulesDir": "auto", + "compilerOptions": { + "lib": ["deno.window"], + "types": ["node"] + }, + "imports": { + "@prisma/adapter-pg": "npm:@prisma/adapter-pg@^7.0.0", + "@prisma/client": "npm:@prisma/client@^7.0.0", + "prisma": "npm:prisma@^7.0.0" + }, + "tasks": { + "dev": "deno run -A --env=.env --watch main.ts", + "db:generate": "deno run -A --env=.env npm:prisma generate", + "db:push": "deno run -A --env=.env npm:prisma db push", + "db:migrate": "deno run -A --env=.env npm:prisma migrate dev", + "db:seed": "deno run -A --env=.env npm:prisma db seed" + } +} +``` + +:::info + +The `nodeModulesDir: "auto"` setting allows Deno to automatically manage a `node_modules` directory, which is needed for Prisma's generated client. The import map entries let you use bare specifiers like `@prisma/client` in your code. + +::: + +## 2. Installing and configuring Prisma + +### 2.1. Initialize Prisma ORM with Prisma Postgres + +Initialize Prisma ORM with Prisma Postgres in your project: + +```bash +deno run -A npm:prisma init --db +``` + +:::info + +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 like "My Deno Project". + +::: + +This command creates: + +- A `prisma/` directory with your `schema.prisma` file +- A new Prisma Postgres database +- A `prisma.config.ts` file +- A `.env` file with your `DATABASE_URL` + +### 2.2. Update the Prisma config file + +Open the generated `prisma.config.ts` file. Since Deno loads environment variables using the `--env=.env` flag (configured in `deno.json` tasks), you can remove the `dotenv/config` import if it was generated: + +```typescript title="prisma.config.ts" +import "dotenv/config"; // [!code --] +import { defineConfig, env } from "prisma/config"; + +export default defineConfig({ + schema: "prisma/schema.prisma", + migrations: { + path: "prisma/migrations", + }, + datasource: { + url: env("DATABASE_URL"), + }, +}); +``` + +### 2.3. Configure environment variables for direct connection + +We're going to use a direct connection string for connecting to Prisma Postgres. To get your [direct connection string](/postgres/database/direct-connections#how-to-connect-to-prisma-postgres-via-direct-tcp): + +1. Navigate to your recently created Prisma Postgres project dashboard (e.g. "My Deno Project") +2. Click the **API Keys** tab in the project's sidebar +3. Click the **Create API key** button +4. Provide a name for the API key and click **Create** +5. Copy the connection string starting with `postgres://` + +Update your `.env` file to replace the `DATABASE_URL` with the new connection string: + +```text title=".env" +DATABASE_URL="your_database_url_here" // [!code --] +DATABASE_URL="your_direct_connection_string_here" // [!code ++] +``` + +### 2.4. Update your Prisma schema + +Open `prisma/schema.prisma` and update it to include the Deno runtime and your data model: + +```prisma title="prisma/schema.prisma" +generator client { + provider = "prisma-client" + output = "../generated/prisma" + runtime = "deno" // [!code ++] +} + +datasource db { + provider = "postgresql" +} + +model User { // [!code ++] + id Int @id @default(autoincrement()) // [!code ++] + email String @unique // [!code ++] + name String? // [!code ++] +} // [!code ++] +``` + +:::note + +The `runtime = "deno"` setting in the generator block is required for Prisma Client to work correctly with the Deno runtime. + +::: + +## 3. Generate Prisma Client and run migrations + +Generate the Prisma Client and apply your schema to the database: + +```bash +deno task db:migrate --name init +deno task db:generate +``` + +This command: + +- Creates the database tables based on your schema +- Generates the Prisma Client in the `generated/prisma` directory + +## 4. Setting up database configuration and creating a seed script + +### 4.1. Create a database utility file + +Create a `db.ts` file in your project root to configure `PrismaClient`: + +```typescript title="db.ts" +import { PrismaClient } from "./generated/prisma/client.ts"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: Deno.env.get("DATABASE_URL")!, +}); + +export const prisma = new PrismaClient({ + adapter, +}); +``` + +### 4.2. Create a seed script + +Create a seed script in the `prisma` folder to populate your database with sample data: + +```typescript title="prisma/seed.ts" +import { PrismaClient } from "../generated/prisma/client.ts"; +import { PrismaPg } from "@prisma/adapter-pg"; + +const adapter = new PrismaPg({ + connectionString: Deno.env.get("DATABASE_URL")!, +}); + +const prisma = new PrismaClient({ + adapter, +}); + +async function main() { + // Create multiple users + await prisma.user.createMany({ + data: [ + { email: "alice@example.com", name: "Alice" }, + { email: "bob@example.com", name: "Bob" }, + { email: "charlie@example.com", name: "Charlie" }, + { email: "diana@example.com", name: "Diana" }, + { email: "eve@example.com", name: "Eve" }, + { email: "frank@example.com", name: "Frank" }, + { email: "grace@example.com", name: "Grace" }, + { email: "henry@example.com", name: "Henry" }, + { email: "isabella@example.com", name: "Isabella" }, + { email: "jack@example.com", name: "Jack" }, + ], + skipDuplicates: true, // prevents errors if you run the seed multiple times + }); + + console.log("Seed data inserted!"); +} + +main() + .catch((e) => { + console.error(e); + Deno.exit(1); + }) + .finally(async () => { + await prisma.$disconnect(); + }); +``` + +### 4.3. Add the seed script to Prisma Config + +Update the `prisma.config.ts` file to include the seed command: + +```typescript title="prisma.config.ts" +import { defineConfig, env } from "prisma/config"; + +export default defineConfig({ + schema: "prisma/schema.prisma", + migrations: { + path: "prisma/migrations", + seed: "deno run -A --env=.env ./prisma/seed.ts", // [!code ++] + }, + datasource: { + url: env("DATABASE_URL"), + }, +}); +``` + +Run the seed script to populate your database: + +```bash +deno task db:seed +``` + +## 5. Creating your Deno server + +Replace the `main.ts` file contents with the following code to build a simple HTTP server that uses Prisma ORM to fetch and display users: + +```typescript title="main.ts" +import { prisma } from "./db.ts"; + +async function handler(req: Request): Promise { + const { pathname } = new URL(req.url); + + // Skip favicon route + if (pathname === "/favicon.ico") { + return new Response(null, { status: 204 }); + } + + // Return all users + const users = await prisma.user.findMany(); + + // Count all users + const count = await prisma.user.count(); + + // Format the response with JSON + return new Response( + JSON.stringify({ + users: users, + totalUsers: count, + }), + { headers: { "Content-Type": "application/json" } }, + ); +} + +Deno.serve({ port: 8000 }, handler); +``` + +## 6. Running your application + +Start your Deno server: + +```bash +deno task dev +``` + +You should see the server running on `http://localhost:8000` in the console. When you visit `http://localhost:8000` in your browser, you'll see a JSON response with all the users in your database and the total count. + +## Next steps + +Now that you have a Deno application connected to a Prisma Postgres database, you can continue by: + +- Extending your Prisma schema with additional models and relationships +- Implementing authentication and authorization +- Adding input validation with Zod +- Exploring Deno's built-in testing tools +- Deploying your application to [Deno Deploy](/guides/integrations/deno) + +### More info + +- [Deno Documentation](https://docs.deno.com) +- [Prisma Config File](/orm/reference/prisma-config-reference) +- [Prisma Postgres](/postgres) diff --git a/apps/docs/content/docs/guides/runtimes/meta.json b/apps/docs/content/docs/guides/runtimes/meta.json index dbc70b8022..a28a3b2a2e 100644 --- a/apps/docs/content/docs/guides/runtimes/meta.json +++ b/apps/docs/content/docs/guides/runtimes/meta.json @@ -1 +1 @@ -{"title":"Runtimes","pages":["bun"]} +{"title":"Runtimes","pages":["bun","deno"]} From a08a0aeba70fd3935789bee3a06e3099647c81f5 Mon Sep 17 00:00:00 2001 From: ArthurGamby Date: Tue, 17 Feb 2026 11:23:12 +0100 Subject: [PATCH 3/3] Revert "docs: add Deno runtime guide" This reverts commit c85b08570da8f07aea13ca380a5d968f17a83655. --- .../content/docs/guides/runtimes/deno.mdx | 317 ------------------ .../content/docs/guides/runtimes/meta.json | 2 +- 2 files changed, 1 insertion(+), 318 deletions(-) delete mode 100644 apps/docs/content/docs/guides/runtimes/deno.mdx diff --git a/apps/docs/content/docs/guides/runtimes/deno.mdx b/apps/docs/content/docs/guides/runtimes/deno.mdx deleted file mode 100644 index 846cb55568..0000000000 --- a/apps/docs/content/docs/guides/runtimes/deno.mdx +++ /dev/null @@ -1,317 +0,0 @@ ---- -title: Deno -description: Learn how to use Prisma ORM in a Deno application with Prisma Postgres -url: /guides/runtimes/deno ---- - -## Introduction - -[Deno](https://deno.com) is a secure JavaScript and TypeScript runtime built on V8 with built-in TypeScript support, a permissions system, and web-standard APIs. In this guide, you will set up a Deno project with Prisma ORM and a Prisma Postgres database. You will create a simple HTTP server that reads from the database and returns the results. - -## Prerequisites - -- [Deno](https://docs.deno.com/runtime/#install-deno) v2.0 or later installed on your system -- A [Prisma Postgres database](/postgres) (created during setup) -- Basic knowledge of JavaScript/TypeScript -- [Deno extension for VS Code](https://docs.deno.com/runtime/reference/vscode/) (recommended) - -## 1. Setting up your Deno project - -First, create a directory for your project and navigate to it: - -```bash -mkdir deno-prisma -cd deno-prisma -``` - -Then, initialize a new Deno project: - -```bash -deno init -``` - -This creates a basic Deno project with a `deno.json` configuration file and a `main.ts` file. - -### 1.1. Configure Deno for Prisma - -Update the `deno.json` file with the following configuration to set up Node.js compatibility, import maps, and Prisma-related task scripts: - -```json title="deno.json" -{ - "nodeModulesDir": "auto", - "compilerOptions": { - "lib": ["deno.window"], - "types": ["node"] - }, - "imports": { - "@prisma/adapter-pg": "npm:@prisma/adapter-pg@^7.0.0", - "@prisma/client": "npm:@prisma/client@^7.0.0", - "prisma": "npm:prisma@^7.0.0" - }, - "tasks": { - "dev": "deno run -A --env=.env --watch main.ts", - "db:generate": "deno run -A --env=.env npm:prisma generate", - "db:push": "deno run -A --env=.env npm:prisma db push", - "db:migrate": "deno run -A --env=.env npm:prisma migrate dev", - "db:seed": "deno run -A --env=.env npm:prisma db seed" - } -} -``` - -:::info - -The `nodeModulesDir: "auto"` setting allows Deno to automatically manage a `node_modules` directory, which is needed for Prisma's generated client. The import map entries let you use bare specifiers like `@prisma/client` in your code. - -::: - -## 2. Installing and configuring Prisma - -### 2.1. Initialize Prisma ORM with Prisma Postgres - -Initialize Prisma ORM with Prisma Postgres in your project: - -```bash -deno run -A npm:prisma init --db -``` - -:::info - -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 like "My Deno Project". - -::: - -This command creates: - -- A `prisma/` directory with your `schema.prisma` file -- A new Prisma Postgres database -- A `prisma.config.ts` file -- A `.env` file with your `DATABASE_URL` - -### 2.2. Update the Prisma config file - -Open the generated `prisma.config.ts` file. Since Deno loads environment variables using the `--env=.env` flag (configured in `deno.json` tasks), you can remove the `dotenv/config` import if it was generated: - -```typescript title="prisma.config.ts" -import "dotenv/config"; // [!code --] -import { defineConfig, env } from "prisma/config"; - -export default defineConfig({ - schema: "prisma/schema.prisma", - migrations: { - path: "prisma/migrations", - }, - datasource: { - url: env("DATABASE_URL"), - }, -}); -``` - -### 2.3. Configure environment variables for direct connection - -We're going to use a direct connection string for connecting to Prisma Postgres. To get your [direct connection string](/postgres/database/direct-connections#how-to-connect-to-prisma-postgres-via-direct-tcp): - -1. Navigate to your recently created Prisma Postgres project dashboard (e.g. "My Deno Project") -2. Click the **API Keys** tab in the project's sidebar -3. Click the **Create API key** button -4. Provide a name for the API key and click **Create** -5. Copy the connection string starting with `postgres://` - -Update your `.env` file to replace the `DATABASE_URL` with the new connection string: - -```text title=".env" -DATABASE_URL="your_database_url_here" // [!code --] -DATABASE_URL="your_direct_connection_string_here" // [!code ++] -``` - -### 2.4. Update your Prisma schema - -Open `prisma/schema.prisma` and update it to include the Deno runtime and your data model: - -```prisma title="prisma/schema.prisma" -generator client { - provider = "prisma-client" - output = "../generated/prisma" - runtime = "deno" // [!code ++] -} - -datasource db { - provider = "postgresql" -} - -model User { // [!code ++] - id Int @id @default(autoincrement()) // [!code ++] - email String @unique // [!code ++] - name String? // [!code ++] -} // [!code ++] -``` - -:::note - -The `runtime = "deno"` setting in the generator block is required for Prisma Client to work correctly with the Deno runtime. - -::: - -## 3. Generate Prisma Client and run migrations - -Generate the Prisma Client and apply your schema to the database: - -```bash -deno task db:migrate --name init -deno task db:generate -``` - -This command: - -- Creates the database tables based on your schema -- Generates the Prisma Client in the `generated/prisma` directory - -## 4. Setting up database configuration and creating a seed script - -### 4.1. Create a database utility file - -Create a `db.ts` file in your project root to configure `PrismaClient`: - -```typescript title="db.ts" -import { PrismaClient } from "./generated/prisma/client.ts"; -import { PrismaPg } from "@prisma/adapter-pg"; - -const adapter = new PrismaPg({ - connectionString: Deno.env.get("DATABASE_URL")!, -}); - -export const prisma = new PrismaClient({ - adapter, -}); -``` - -### 4.2. Create a seed script - -Create a seed script in the `prisma` folder to populate your database with sample data: - -```typescript title="prisma/seed.ts" -import { PrismaClient } from "../generated/prisma/client.ts"; -import { PrismaPg } from "@prisma/adapter-pg"; - -const adapter = new PrismaPg({ - connectionString: Deno.env.get("DATABASE_URL")!, -}); - -const prisma = new PrismaClient({ - adapter, -}); - -async function main() { - // Create multiple users - await prisma.user.createMany({ - data: [ - { email: "alice@example.com", name: "Alice" }, - { email: "bob@example.com", name: "Bob" }, - { email: "charlie@example.com", name: "Charlie" }, - { email: "diana@example.com", name: "Diana" }, - { email: "eve@example.com", name: "Eve" }, - { email: "frank@example.com", name: "Frank" }, - { email: "grace@example.com", name: "Grace" }, - { email: "henry@example.com", name: "Henry" }, - { email: "isabella@example.com", name: "Isabella" }, - { email: "jack@example.com", name: "Jack" }, - ], - skipDuplicates: true, // prevents errors if you run the seed multiple times - }); - - console.log("Seed data inserted!"); -} - -main() - .catch((e) => { - console.error(e); - Deno.exit(1); - }) - .finally(async () => { - await prisma.$disconnect(); - }); -``` - -### 4.3. Add the seed script to Prisma Config - -Update the `prisma.config.ts` file to include the seed command: - -```typescript title="prisma.config.ts" -import { defineConfig, env } from "prisma/config"; - -export default defineConfig({ - schema: "prisma/schema.prisma", - migrations: { - path: "prisma/migrations", - seed: "deno run -A --env=.env ./prisma/seed.ts", // [!code ++] - }, - datasource: { - url: env("DATABASE_URL"), - }, -}); -``` - -Run the seed script to populate your database: - -```bash -deno task db:seed -``` - -## 5. Creating your Deno server - -Replace the `main.ts` file contents with the following code to build a simple HTTP server that uses Prisma ORM to fetch and display users: - -```typescript title="main.ts" -import { prisma } from "./db.ts"; - -async function handler(req: Request): Promise { - const { pathname } = new URL(req.url); - - // Skip favicon route - if (pathname === "/favicon.ico") { - return new Response(null, { status: 204 }); - } - - // Return all users - const users = await prisma.user.findMany(); - - // Count all users - const count = await prisma.user.count(); - - // Format the response with JSON - return new Response( - JSON.stringify({ - users: users, - totalUsers: count, - }), - { headers: { "Content-Type": "application/json" } }, - ); -} - -Deno.serve({ port: 8000 }, handler); -``` - -## 6. Running your application - -Start your Deno server: - -```bash -deno task dev -``` - -You should see the server running on `http://localhost:8000` in the console. When you visit `http://localhost:8000` in your browser, you'll see a JSON response with all the users in your database and the total count. - -## Next steps - -Now that you have a Deno application connected to a Prisma Postgres database, you can continue by: - -- Extending your Prisma schema with additional models and relationships -- Implementing authentication and authorization -- Adding input validation with Zod -- Exploring Deno's built-in testing tools -- Deploying your application to [Deno Deploy](/guides/integrations/deno) - -### More info - -- [Deno Documentation](https://docs.deno.com) -- [Prisma Config File](/orm/reference/prisma-config-reference) -- [Prisma Postgres](/postgres) diff --git a/apps/docs/content/docs/guides/runtimes/meta.json b/apps/docs/content/docs/guides/runtimes/meta.json index a28a3b2a2e..dbc70b8022 100644 --- a/apps/docs/content/docs/guides/runtimes/meta.json +++ b/apps/docs/content/docs/guides/runtimes/meta.json @@ -1 +1 @@ -{"title":"Runtimes","pages":["bun","deno"]} +{"title":"Runtimes","pages":["bun"]}