You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feat: DR-6472 SQLite MySQL added to embedded studio docs (#7430)
* Added SQLite and MySQL to embedding studio docs
* Added SQLite and MySQL to embedding studio guide docs
* Possible over promise removed
* unneeded import removed
* broken link removed
* Update content/800-guides/360-embed-studio-nextjs.mdx
---------
Co-authored-by: Ankur Datta <64993082+ankur-arch@users.noreply.github.com>
Prisma Studio can be embedded in your own application via the [`@prisma/studio-core`](https://www.npmjs.com/package/@prisma/studio-core) package.
12
12
13
-
It provides `Studio`, a React component which renders Prisma Studio for your database. The `Studio` component accepts an executor that calls a `/studio` endpoint in your backend. The backend uses your `DATABASE_URL` (connection string) to connect to the correct Prisma Postgres instance and execute the SQL query.
13
+
It provides `Studio`, a React component which renders Prisma Studio for your database. The `Studio` component accepts an executor that calls a `/studio` endpoint in your backend. The backend uses your `DATABASE_URL` (connection string) to connect to the correct database instance (PostgreSQL, SQLite, or MySQL) and execute the SQL query.
14
14
15
15
:::tip
16
16
If you want to see what embedded Studio looks like, **[check out the demo](https://github.com/prisma/studio-core-demo) on GitHub**!
@@ -29,29 +29,53 @@ You can embed Prisma Studio in your own app in various scenarios:
29
29
- Frontend: A React application
30
30
- Backend:
31
31
- A server-side application to expose the `/studio` endpoint (e.g. with Express or Hono)
32
-
- A Prisma Postgres instance (you can create one with `npx prisma init --db`)
32
+
- A database instance (PostgreSQL, SQLite, or MySQL)
33
+
34
+
## Database support
35
+
36
+
Embedded Prisma Studio supports the following databases:
37
+
38
+
-**PostgreSQL**
39
+
-**SQLite**
40
+
-**MySQL**
33
41
34
42
:::note
35
-
The embeddable version of Prisma Studio will be available for other databases in combination with Prisma ORM soon.
43
+
The implementation pattern is similar across all databases - you just need to use the appropriate executor and adapter for your database type.
36
44
:::
37
45
38
46
## Installation
39
47
40
48
Install the npm package:
41
49
42
-
```terminal
50
+
```bash
43
51
npm install @prisma/studio-core
44
52
```
45
53
54
+
### Additional dependencies
55
+
56
+
Depending on your database type, you may need additional packages:
57
+
58
+
```bash
59
+
# For SQLite support
60
+
npm install better-sqlite3
61
+
62
+
# For MySQL support
63
+
npm install mysql2
64
+
```
65
+
66
+
PostgreSQL support is included with `@prisma/studio-core` and requires no additional dependencies.
67
+
46
68
## Frontend setup
47
69
48
70
In your React app, you can use the `Studio` component to render the tables in your database via Prisma Studio. It receives an _executor_ which is responsible for packaging the current SQL query in an HTTP request (also allowing for custom headers/payloads) and sending it to the `/studio` endpoint in your backend.
49
71
72
+
The implementation varies slightly depending on your database type. Choose the appropriate section below:
73
+
50
74
> Check out the [demo](https://github.com/prisma/studio-core-demo/blob/main/frontend/index.tsx) on GitHub for a full reference implementation.
51
75
52
-
### Minimal implementation
76
+
### PostgreSQL implementation
53
77
54
-
Here's what a minimal implementation looks like:
78
+
Here's what a minimal implementation looks like for PostgreSQL:
55
79
56
80
```tsx
57
81
import { Studio } from"@prisma/studio-core/ui";
@@ -79,9 +103,69 @@ function App() {
79
103
}
80
104
```
81
105
106
+
### SQLite implementation
107
+
108
+
Here's what a minimal implementation looks like for SQLite:
-**Adapter**: Handles database-specific query formatting (PostgreSQL, SQLite, or MySQL)
178
264
-**Custom headers**: Pass authentication tokens, user info, etc.
179
265
-**Custom payload**: Send additional context/data with each request
180
266
181
267
## Backend setup
182
268
183
-
Your backend needs to expose a `/studio` endpoint where the frontend sends its requests. The implementation below uses `createPrismaPostgresHttpClient` from `@prisma/studio-core`.
269
+
Your backend needs to expose a `/studio` endpoint where the frontend sends its requests. The implementation varies depending on your database type. Choose the appropriate section below:
184
270
185
-
The backend also needs to have access to the Prisma Postgres API key, we recommend setting it as an environment variable as a best practice.
271
+
### PostgreSQL backend implementation
272
+
273
+
The PostgreSQL implementation uses `createPrismaPostgresHttpClient` from `@prisma/studio-core`. This works with Prisma Postgres or any PostgreSQL instance.
186
274
187
275
> Check out the [demo](https://github.com/prisma/studio-core-demo/blob/main/server/index.ts) on GitHub for a full reference implementation.
The SQLite implementation uses `createNodeSQLiteExecutor` from `@prisma/studio-core` and requires the `better-sqlite3` package. This works with local SQLite database files.
Here's what a slightly more advanced implementation for the `/studio` endpoint looks like with [Hono](https://hono.dev/). In this case, a multi-tenant scenario is assumed where the frontend sends over a user ID and authentication token which is used on the backend to determine the Prisma Postgres instance that belongs to that user via a hypothetical `determineUrlFromContext` function:
394
+
Here's what a slightly more advanced implementation for the `/studio` endpoint looks like with [Hono](https://hono.dev/). In this case, a multi-tenant scenario is assumed where the frontend sends over a user ID and authentication token which is used on the backend to determine the database instance that belongs to that user via a hypothetical `determineUrlFromContext` function:
0 commit comments