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 289ee857df..71006ab8cf 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 @@ -31,6 +31,10 @@ npm install prisma @types/node @types/better-sqlite3 --save-dev npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv ``` +:::note[pnpm users with SQLite] +If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag when running Prisma Studio due to SQLite's native dependency requirements. +::: + Here's what each package does: - **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate` @@ -267,9 +271,25 @@ You should see the created user and all users printed to the console! :::note[SQLite requirements for Prisma Studio] - File paths must have a `file:` protocol right now in the database url for SQLite -- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module -- Node.js 20: Requires installing `better-sqlite3` as a dependency - - If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script +- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module + - May require `NODE_OPTIONS=--experimental-sqlite` environment variable +- **Node.js 20**: Requires installing `better-sqlite3` as a dependency + - If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag +- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/) +- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet + +:::tip[Using `npx` with `better-sqlite3`] + +If you don't have `node:sqlite` available in your runtime or prefer not to install `better-sqlite3` as a hard dependency (it adds ~10MB), you can use `npx` to temporarily install the required packages: + +```terminal +npx -p better-sqlite3 -p prisma prisma studio --url file:./dev.db +``` + +This command: +- Temporarily installs `better-sqlite3` without adding it to your project dependencies +- Runs Prisma Studio with the specified SQLite database file +- Avoids the 10MB overhead of `better-sqlite3` in your project ::: 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 2730ac382c..fbdafa6a4d 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 @@ -252,9 +252,25 @@ This command will: :::note[SQLite requirements for Prisma Studio] - File paths must have a `file:` protocol right now in the database url for SQLite -- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module -- Node.js 20: Requires installing `better-sqlite3` as a dependency - - If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script +- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module + - May require `NODE_OPTIONS=--experimental-sqlite` environment variable +- **Node.js 20**: Requires installing `better-sqlite3` as a dependency + - If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag +- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/) +- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet + +:::tip[Using `npx` with `better-sqlite3`] + +If you don't have `node:sqlite` available in your runtime or prefer not to install `better-sqlite3` as a hard dependency (it adds ~10MB), you can use `npx` to temporarily install the required packages: + +```terminal +npx -p better-sqlite3 -p prisma prisma studio --url file:./path/to/your/database.db +``` + +This command: +- Temporarily installs `better-sqlite3` without adding it to your project dependencies +- Runs Prisma Studio with the specified SQLite database file +- Avoids the 10MB overhead of `better-sqlite3` in your project ::: diff --git a/content/200-orm/400-tools/06-prisma-studio.mdx b/content/200-orm/400-tools/06-prisma-studio.mdx index 95832603ab..b54aff4053 100644 --- a/content/200-orm/400-tools/06-prisma-studio.mdx +++ b/content/200-orm/400-tools/06-prisma-studio.mdx @@ -134,9 +134,27 @@ Prisma Studio currently supports the following databases: PostgreSQL, MySQL, and ### SQLite requirements for Prisma Studio - File paths must have a `file:` protocol right now in the database url for SQLite -- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module -- Node.js 20: Requires installing `better-sqlite3` as a dependency - - If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script +- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module + - May require `NODE_OPTIONS=--experimental-sqlite` environment variable +- **Node.js 20**: Requires installing `better-sqlite3` as a dependency + - If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag +- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/) +- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet + +:::tip[Using `npx` with `better-sqlite3`] + +If you don't have `node:sqlite` available in your runtime or prefer not to install `better-sqlite3` as a hard dependency (it adds ~10MB), you can use `npx` to temporarily install the required packages: + +```terminal +npx -p better-sqlite3 -p prisma prisma studio --url file:./my_file.db +``` + +This command: +- Temporarily installs `better-sqlite3` without adding it to your project dependencies +- Runs Prisma Studio with the specified SQLite database file +- Avoids the 10MB overhead of `better-sqlite3` in your project + +::: ### Databases not yet supported diff --git a/content/250-postgres/300-database/750-serverless-driver.mdx b/content/250-postgres/300-database/750-serverless-driver.mdx index 7911abfdd7..6423a1c290 100644 --- a/content/250-postgres/300-database/750-serverless-driver.mdx +++ b/content/250-postgres/300-database/750-serverless-driver.mdx @@ -150,18 +150,39 @@ With 100ms network latency, 3 sequential queries take 300ms (3 x RTT), but pipel ### Parameter streaming -Parameters over 1KB are automatically streamed without buffering in memory: +Parameters over 1KB are automatically streamed without buffering in memory. For large binary parameters, you must use `boundedByteStreamParameter()` which creates a `BoundedByteStreamParameter` object that carries the total byte size, required by the PostgreSQL protocol: ```ts -// Large text content (e.g., 10MB document) -const largeDocument = generateLargeText() +import { client, defaultClientConfig, boundedByteStreamParameter, BINARY } from "@prisma/ppg" + +const cl = client(defaultClientConfig(process.env.PRISMA_DIRECT_TCP_URL!)) + +// Large binary data (e.g., file content) +const stream = getReadableStream() // Your ReadableStream source +const totalSize = 1024 * 1024 // Total size must be known in advance + +// Create a bounded byte stream parameter +const streamParam = boundedByteStreamParameter(stream, BINARY, totalSize) // Automatically streamed - constant memory usage -await ppg.sql.exec` - INSERT INTO documents (content) VALUES (${largeDocument}) -` +await cl.query("INSERT INTO files (data) VALUES ($1)", streamParam) ``` +For `Uint8Array` data, use `byteArrayParameter()`: + +```ts +import { client, defaultClientConfig, byteArrayParameter, BINARY } from "@prisma/ppg" + +const cl = client(defaultClientConfig(process.env.PRISMA_DIRECT_TCP_URL!)) + +const bytes = new Uint8Array([1, 2, 3, 4]) +const param = byteArrayParameter(bytes, BINARY) + +await cl.query("INSERT INTO files (data) VALUES ($1)", param) +``` + +The `boundedByteStreamParameter()` function is provided by the `@prisma/ppg` library and requires the total byte size to be known in advance due to PostgreSQL protocol requirements. + ### Transactions and batch operations Transactions automatically handle BEGIN, COMMIT, and ROLLBACK: