-
Notifications
You must be signed in to change notification settings - Fork 870
Feat: DR-6472 SQLite MySQL added to embedded studio docs #7430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Dangerous URL checkNo absolute URLs to prisma.io/docs found. |
WalkthroughThe docs were expanded from PostgreSQL-only to multi-database embedding: Prisma Studio embedding and Next.js guide now support PostgreSQL, SQLite, and MySQL, replacing Postgres-specific wording with database-agnostic terminology and adding per-database examples and setup steps. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Redirect checkThis PR probably requires the following redirects to be added to static/_redirects:
|
Deploying docs with
|
| Latest commit: |
acb9dc2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f2f5907a.docs-51g.pages.dev |
| Branch Preview URL: | https://feat-dr-6472-sqlite-mysql-em.docs-51g.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (7)
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx (5)
23-25: Fix grammar: “a quick admin dashboard”.Line 23: “Create an quick…” → “Create a quick…”.
80-165: All three frontend snippets useuseMemobut don’t import it (copy/paste break).Each TSX example calls
useMemo(...)but never imports it from React. Consider addingimport { useMemo } from "react";(orimport React, { useMemo } ...) to each snippet to make them runnable.Proposed fix (apply similarly to SQLite/MySQL snippets)
import { Studio } from "@prisma/studio-core/ui"; import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core"; import { createStudioBFFClient } from "@prisma/studio-core/data/bff"; +import { useMemo } from "react"; import "@prisma/studio-core/ui/index.css"
404-430: Avoid logging headers/payload in auth examples (risk of leaking secrets/PII).Lines 410-413
console.logrequest-derived values; readers often copy/paste this into prod. Consider removing logs or explicitly warning to never log auth tokens / sensitive identifiers.
279-305: Add validation forDATABASE_URLin the PostgreSQL backend implementation to match SQLite and MySQL patterns.The PostgreSQL section omits the
DATABASE_URLvalidation that both the SQLite and MySQL sections include. This creates an inconsistency whereundefinedgets silently passed tocreatePrismaPostgresHttpClient, leading to a less obvious error message. Adding the validation ensures consistent, clear error handling across all database backends.Proposed fix
// 2. Read DB URL from env vars const url = process.env.DATABASE_URL; + if (!url) { + return c.json([serializeError(new Error("DATABASE_URL is missing"))], 500); + } + // 3. Execute the query against Prisma Postgres const [error, results] = await createPrismaPostgresHttpClient({ url }).execute(query);
170-193: Add missing imports for SQLite and MySQL adapters so switching database types actually works.The snippet advertises support for all database types but only imports the PostgreSQL adapter. Lines 191–192 show
createSQLiteAdapterandcreateMySQLAdaptercommented out, but if a developer uncomments either line, they'll get aReferenceErrorbecause those functions aren't imported.Since the section claims to "work for all database types," either add the missing imports at the top or rewrite the snippet to clarify that developers must replace the Postgres import and call with the database adapter of their choice.
Proposed fix
import { Studio } from "@prisma/studio-core/ui"; import { createPostgresAdapter } from "@prisma/studio-core/data/postgres-core"; +import { createSQLiteAdapter } from "@prisma/studio-core/data/sqlite-core"; +import { createMySQLAdapter } from "@prisma/studio-core/data/mysql-core"; import { createStudioBFFClient } from "@prisma/studio-core/data/bff"; import "@prisma/studio-core/ui/index.css"content/800-guides/360-embed-studio-nextjs.mdx (2)
571-576: CORS header example is dangerously permissive for a “production-ready” guide.
Access-Control-Allow-Origin: "*"(Line 572) is fine for a toy demo, but this endpoint executes arbitrary queries. Consider adding a bold warning + show a locked-down example origin (or recommend same-origin only, since it’s/api/studioin the same Next app).
159-168: Schema snippet is incomplete and misleading: missing requiredurlfield and lacks database variants.The
datasourceblock at lines 165–167 omits the requiredurlfield and only showsprovider = "postgresql". While the init command earlier (section 2.2) demonstrates multi-database options via--datasource-provider, the schema snippet doesn't reflect this. According to Prisma configuration requirements, the datasource block must includeurl.Although
prisma.config.tslater provides the URL viadatasource: { url: env("DATABASE_URL") }, the schema.prisma snippet should be self-contained. Update the snippet to either:
- Include
url = env("DATABASE_URL")in the datasource block, and/or- Show tabbed variants for PostgreSQL, SQLite, and MySQL to match the init command options presented earlier.
🤖 Fix all issues with AI agents
In
@content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx:
- Around line 13-14: Change the misleading comment that reads "Execute the query
against Prisma Postgres" to "Execute the query against PostgreSQL" so it doesn't
imply exclusivity; update the comment located near the implementation or usage
of createPrismaPostgresHttpClient (and any similar doc string referencing Prisma
Postgres) to reflect that the executor works with any PostgreSQL instance, not
only Prisma-managed Postgres.
- Around line 54-67: The sentence claiming "PostgreSQL support is included with
`@prisma/studio-core` and requires no additional dependencies" should be
softened and clarified: change it to indicate that `@prisma/studio-core` bundles
PostgreSQL support at the library level but that running Studio in a backend
still requires a working Postgres connection and typical backend tooling (for
example using `Prisma Client`) will still need the `pg` driver or other
infrastructure-level dependencies; mention `@prisma/studio-core`, `Prisma
Client`, and `pg` to guide readers.
- Around line 311-348: The handler currently strips the file URI with
url.replace("file:", "") and creates a new better-sqlite3 Database per request;
change this by using an anchored regex to remove only a leading "file:" (e.g.,
dbPath = DATABASE_URL.replace(/^file:/, "")) and move DatabaseSync instantiation
out of app.post("/studio") so a single DatabaseSync instance is created once (at
module scope) and reused; update references to dbPath/DATABASE_URL and keep
createNodeSQLiteExecutor(database).execute(query) inside the handler, and add a
brief comment documenting the expected DATABASE_URL format (e.g.,
"file:./dev.db").
In @content/800-guides/360-embed-studio-nextjs.mdx:
- Around line 145-154: The heading "### 2.2. What the init command creates" is
duplicated; rename that heading to "### 2.3. What the init command creates" and
increment the numbering of subsequent section headings accordingly to restore
sequential numbering and stable anchors; locate the heading by the exact text
"What the init command creates" and update any following "2.2" occurrences in
this file to the next numbers (e.g., 2.3 → 2.4, etc.) so all section numbers
remain consistent.
- Around line 84-113: The MySQL TabItem contains an incorrect dev dependency
"@types/mysql2" which doesn't exist and breaks installs; edit the TabItem with
value="mysql" (the MySQL install block) to remove "@types/mysql2" from the dev
install command so it reads only "npm install prisma tsx --save-dev" while
keeping the runtime installs (e.g., @prisma/client @prisma/adapter-mysql dotenv
mysql2) unchanged.
🧹 Nitpick comments (3)
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx (1)
354-390: MySQL pool created per request (connection churn) — prefer a single shared pool.Line 375 creates a new pool for every request; that’s both slow and can exhaust connections. Even in docs, a “minimal but safe” pattern would define
const pool = mysql.createPool(url)once (or cache by tenant) and reuse it.content/800-guides/360-embed-studio-nextjs.mdx (2)
426-485: Good: datasource url differs by DB — but call out the env var expectation earlier.Postgres uses
env('DIRECT_URL')(Line 440) while SQLite/MySQL useenv('DATABASE_URL')(Lines 459, 478). That’s correct for many Prisma Postgres setups, but earlier sections emphasize onlyDATABASE_URL; consider a short note that Prisma Postgres commonly needs bothDATABASE_URLandDIRECT_URL(what each is used for).
566-632: Next.js route handler examples: avoiddotenv/config, and don’t create DB/pool per request.
- In Next.js,
.envis loaded by the framework;import "dotenv/config"insideroute.tsis usually unnecessary and sometimes confusing.- SQLite/MySQL examples create a DB handle / pool on every request; that’s costly and can exhaust connections. Prefer module-level singletons (or cached per tenant) in the example.
Also applies to: 638-706, 711-777
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdxcontent/800-guides/360-embed-studio-nextjs.mdx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-06T22:06:57.725Z
Learnt from: newclarityex
Repo: prisma/docs PR: 7425
File: content/200-orm/050-overview/500-databases/400-mysql.mdx:80-80
Timestamp: 2026-01-06T22:06:57.725Z
Learning: In Prisma docs, when showing examples of instantiating driver adapters with connection strings from environment variables, use the template literal pattern `const connectionString = `${process.env.DATABASE_URL}`` for consistency across all database adapter examples (PostgreSQL, MySQL/MariaDB, etc.).
Applied to files:
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdxcontent/800-guides/360-embed-studio-nextjs.mdx
🪛 LanguageTool
content/800-guides/360-embed-studio-nextjs.mdx
[style] ~560-~560: Consider a more expressive alternative.
Context: ...s (or errors) back to the frontend. To do this, create a new folder called api ...
(DO_ACHIEVE)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Check internal links
- GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
content/800-guides/360-embed-studio-nextjs.mdx (1)
232-418: Align seed script environment variables with guide context; Postgres tab doesn't requireDIRECT_URLin adapter instantiation.The seed script's use of
process.env.DATABASE_URL!is correct for runtime adapter code. The@prisma/adapter-pgadapter instantiation receives aconnectionStringparameter directly—it doesn't read fromschema.prismaorprisma.config.ts. TheDIRECT_URLin theprisma.config.tsdatasource (line 440) is for Prisma CLI operations like migrations, not for runtime seed scripts.However, there's a real inconsistency in the guide: the Postgres
prisma.config.tsspecifiesenv('DIRECT_URL')while the seed script and SQLite/MySQL examples useenv('DATABASE_URL'). For clarity and consistency, either:
- Simplify: Use
env('DATABASE_URL')across all three tabs inprisma.config.ts(matches whatprisma initcreates and what seeds use), or- Document: Explain why Postgres uses
DIRECT_URLin the config and clarify that users should set bothDATABASE_URL(for runtime) andDIRECT_URL(for CLI) in their.env.The stylistic suggestion to use
const connectionString = \${process.env.DATABASE_URL}`for consistency across all three seed tabs is reasonable, but the core fix is addressing theDIRECT_URL` inconsistency at the guide level, not in the seeds.Likely an incorrect or invalid review comment.
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx
Show resolved
Hide resolved
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx
Show resolved
Hide resolved
content/250-postgres/300-database/675-prisma-studio/100-embedding-studio.mdx
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @content/800-guides/360-embed-studio-nextjs.mdx:
- Around line 754-756: The code creates a new MySQL pool on every request by
calling mysql.createPool(...) inside the request handler; move the pool creation
out of the per-request flow so a single shared pool is reused across requests
(e.g., create a module-level or singleton pool variable and initialize it once),
then pass that reusable pool into createMySQL2Executor(pool).execute(query)
instead of recreating mysql.createPool for each POST.
- Around line 84-113: The package names for the SQLite and MySQL Prisma adapters
in the TabItem blocks are incorrect; update the SQLite install line to use the
actual adapter package name @prisma/adapter-better-sqlite3 (replace
@prisma/adapter-sqlite) and update the MySQL install line to use
@prisma/adapter-mariadb (replace @prisma/adapter-mysql) so the TabItem blocks
labeled "SQLite" and "MySQL" list the correct npm packages to install.
🧹 Nitpick comments (3)
content/800-guides/360-embed-studio-nextjs.mdx (3)
166-166: Clarify the datasource provider for multi-database examples.The comment states the provider "will change depending on the --datasource-provider flag," but the value shown is
"postgresql". For a multi-database guide, consider using a placeholder comment or showing all three options to reduce confusion.📝 Suggested clarification
datasource db { - provider = "postgresql" // this will change depending on the --datasource-provider flag used in the init command + provider = "postgresql" // or "sqlite" or "mysql" depending on the --datasource-provider flag used in the init command }
682-683: Strengthen SQLite file path extraction.The simple string replacement
url.replace("file:", "")may fail with variations likefile://, relative paths, or query parameters. Consider using a more robust URL parsing approach.🔧 Proposed improvement using URL parsing
// Execute query using SQLite - const dbPath = url.replace("file:", ""); + const dbPath = url.startsWith("file:") + ? new URL(url).pathname + : url; const database = new DatabaseSync(dbPath); const [error, results] = await createNodeSQLiteExecutor(database).execute(query);
236-237: Consider template literal pattern for consistency.Based on learnings, Prisma docs prefer the template literal pattern for connection strings:
const connectionString = `${process.env.DATABASE_URL}`. While the current direct reference works, using the template literal would provide better consistency across documentation examples.Additionally, the non-null assertion (
!) assumesDATABASE_URLis always defined. Consider adding a runtime check for better error handling.♻️ Suggested pattern for consistency
For PostgreSQL adapter (similar for SQLite and MySQL):
+const connectionString = `${process.env.DATABASE_URL}` + +if (!connectionString) { + throw new Error('DATABASE_URL environment variable is required') +} + const adapter = new PrismaPg({ - connectionString: process.env.DATABASE_URL!, + connectionString, })Based on learnings, the template literal pattern provides consistency across all database adapter examples.
Also applies to: 300-301, 364-365
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
content/800-guides/360-embed-studio-nextjs.mdx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-06T22:06:57.725Z
Learnt from: newclarityex
Repo: prisma/docs PR: 7425
File: content/200-orm/050-overview/500-databases/400-mysql.mdx:80-80
Timestamp: 2026-01-06T22:06:57.725Z
Learning: In Prisma docs, when showing examples of instantiating driver adapters with connection strings from environment variables, use the template literal pattern `const connectionString = `${process.env.DATABASE_URL}`` for consistency across all database adapter examples (PostgreSQL, MySQL/MariaDB, etc.).
Applied to files:
content/800-guides/360-embed-studio-nextjs.mdx
🪛 LanguageTool
content/800-guides/360-embed-studio-nextjs.mdx
[style] ~560-~560: Consider a more expressive alternative.
Context: ...s (or errors) back to the frontend. To do this, create a new folder called api ...
(DO_ACHIEVE)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
content/800-guides/360-embed-studio-nextjs.mdx (3)
428-485: This is correct and intentional documentation.The
DIRECT_URLfor Prisma Postgres is specifically for use with connection pooling. Prisma separates concerns:DIRECT_URLis used by Prisma CLI commands (migrations, introspection) which need direct database access, whileDATABASE_URLis used by the application at runtime. This pattern is documented throughout the Prisma guides (Supabase, Neon, PgBouncer, etc.). SQLite doesn't use connection pooling, soDATABASE_URLis appropriate for direct connections. There are no seed files in this documentation repository to verify the secondary claim about seed file references.
827-827: Adapter function names are correct.The code correctly uses
createPostgresAdapter,createSQLiteAdapter, andcreateMySQLAdapterfrom their respective@prisma/studio-core/data/*modules (postgres-core, sqlite-core, mysql-core). These functions are documented and follow Prisma Studio Core's standard adapter factory pattern.
609-611: All executor function names are correct and already in use.Verification confirms that all three executor functions from
@prisma/studio-coreare correctly named and properly utilized in the code:
createPrismaPostgresHttpClient(line 609) ✓createNodeSQLiteExecutor(line 684) ✓createMySQL2Executor(line 756) ✓Each follows the expected pattern of instantiation with database-specific configuration followed by
.execute(query). No corrections needed.
Summary by CodeRabbit
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.