Skip to content

Commit b7860f3

Browse files
ankur-archaidankmcalister
authored andcommitted
fix: add SQLite notes (#7277)
* fix: add SQLite notes * fix: update serverless driver doc * feat: add callout
1 parent 9b0c57d commit b7860f3

File tree

4 files changed

+90
-15
lines changed

4 files changed

+90
-15
lines changed

content/100-getting-started/02-prisma-orm/100-quickstart/200-sqlite.mdx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ npm install prisma @types/node @types/better-sqlite3 --save-dev
3131
npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv
3232
```
3333

34+
:::note[pnpm users with SQLite]
35+
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.
36+
:::
37+
3438
Here's what each package does:
3539

3640
- **`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!
267271

268272
:::note[SQLite requirements for Prisma Studio]
269273
- File paths must have a `file:` protocol right now in the database url for SQLite
270-
- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module
271-
- Node.js 20: Requires installing `better-sqlite3` as a dependency
272-
- If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script
274+
- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module
275+
- May require `NODE_OPTIONS=--experimental-sqlite` environment variable
276+
- **Node.js 20**: Requires installing `better-sqlite3` as a dependency
277+
- If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag
278+
- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/)
279+
- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet
280+
281+
:::tip[Using `npx` with `better-sqlite3`]
282+
283+
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:
284+
285+
```terminal
286+
npx -p better-sqlite3 -p prisma prisma studio --url file:./dev.db
287+
```
288+
289+
This command:
290+
- Temporarily installs `better-sqlite3` without adding it to your project dependencies
291+
- Runs Prisma Studio with the specified SQLite database file
292+
- Avoids the 10MB overhead of `better-sqlite3` in your project
273293

274294
:::
275295

content/100-getting-started/02-prisma-orm/200-add-to-existing-project/200-sqlite.mdx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,25 @@ This command will:
252252
:::note[SQLite requirements for Prisma Studio]
253253

254254
- File paths must have a `file:` protocol right now in the database url for SQLite
255-
- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module
256-
- Node.js 20: Requires installing `better-sqlite3` as a dependency
257-
- If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script
255+
- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module
256+
- May require `NODE_OPTIONS=--experimental-sqlite` environment variable
257+
- **Node.js 20**: Requires installing `better-sqlite3` as a dependency
258+
- If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag
259+
- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/)
260+
- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet
261+
262+
:::tip[Using `npx` with `better-sqlite3`]
263+
264+
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:
265+
266+
```terminal
267+
npx -p better-sqlite3 -p prisma prisma studio --url file:./path/to/your/database.db
268+
```
269+
270+
This command:
271+
- Temporarily installs `better-sqlite3` without adding it to your project dependencies
272+
- Runs Prisma Studio with the specified SQLite database file
273+
- Avoids the 10MB overhead of `better-sqlite3` in your project
258274

259275
:::
260276

content/200-orm/400-tools/06-prisma-studio.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,27 @@ Prisma Studio currently supports the following databases: PostgreSQL, MySQL, and
134134
### SQLite requirements for Prisma Studio
135135

136136
- File paths must have a `file:` protocol right now in the database url for SQLite
137-
- Node.js 22.5+: Works out of the box with the built-in `node:sqlite` module
138-
- Node.js 20: Requires installing `better-sqlite3` as a dependency
139-
- If using pnpm 10+, you'll also need to allow the `better-sqlite3` install script
137+
- **Node.js 22.5+**: Works out of the box with the built-in `node:sqlite` module
138+
- May require `NODE_OPTIONS=--experimental-sqlite` environment variable
139+
- **Node.js 20**: Requires installing `better-sqlite3` as a dependency
140+
- If using pnpm 10+ with `pnpx`, you'll need the [`--allow-build=better-sqlite3`](https://pnpm.io/cli/dlx#--allow-build) flag
141+
- **Deno >= 2.2**: Supported via [built-in SQLite module](https://docs.deno.com/api/node/sqlite/)
142+
- **Bun**: Support for Prisma Studio with SQLite is coming soon and is not available yet
143+
144+
:::tip[Using `npx` with `better-sqlite3`]
145+
146+
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:
147+
148+
```terminal
149+
npx -p better-sqlite3 -p prisma prisma studio --url file:./my_file.db
150+
```
151+
152+
This command:
153+
- Temporarily installs `better-sqlite3` without adding it to your project dependencies
154+
- Runs Prisma Studio with the specified SQLite database file
155+
- Avoids the 10MB overhead of `better-sqlite3` in your project
156+
157+
:::
140158

141159
### Databases not yet supported
142160

content/250-postgres/300-database/750-serverless-driver.mdx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,39 @@ With 100ms network latency, 3 sequential queries take 300ms (3 x RTT), but pipel
150150

151151
### Parameter streaming
152152

153-
Parameters over 1KB are automatically streamed without buffering in memory:
153+
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:
154154

155155
```ts
156-
// Large text content (e.g., 10MB document)
157-
const largeDocument = generateLargeText()
156+
import { client, defaultClientConfig, boundedByteStreamParameter, BINARY } from "@prisma/ppg"
157+
158+
const cl = client(defaultClientConfig(process.env.PRISMA_DIRECT_TCP_URL!))
159+
160+
// Large binary data (e.g., file content)
161+
const stream = getReadableStream() // Your ReadableStream source
162+
const totalSize = 1024 * 1024 // Total size must be known in advance
163+
164+
// Create a bounded byte stream parameter
165+
const streamParam = boundedByteStreamParameter(stream, BINARY, totalSize)
158166

159167
// Automatically streamed - constant memory usage
160-
await ppg.sql.exec`
161-
INSERT INTO documents (content) VALUES (${largeDocument})
162-
`
168+
await cl.query("INSERT INTO files (data) VALUES ($1)", streamParam)
163169
```
164170

171+
For `Uint8Array` data, use `byteArrayParameter()`:
172+
173+
```ts
174+
import { client, defaultClientConfig, byteArrayParameter, BINARY } from "@prisma/ppg"
175+
176+
const cl = client(defaultClientConfig(process.env.PRISMA_DIRECT_TCP_URL!))
177+
178+
const bytes = new Uint8Array([1, 2, 3, 4])
179+
const param = byteArrayParameter(bytes, BINARY)
180+
181+
await cl.query("INSERT INTO files (data) VALUES ($1)", param)
182+
```
183+
184+
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.
185+
165186
### Transactions and batch operations
166187

167188
Transactions automatically handle BEGIN, COMMIT, and ROLLBACK:

0 commit comments

Comments
 (0)