Skip to content

Commit 6d44921

Browse files
feat: add Prisma Compute examples (#8556)
* feat: add Prisma Compute examples Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com> * chore: refresh Prisma Compute examples Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com> * fix: use project env for Compute examples Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com> * chore: refresh Prisma Compute example scripts Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com> --------- Signed-off-by: Aman Varshney <amanvarshney.work@gmail.com>
1 parent 663c23c commit 6d44921

43 files changed

Lines changed: 1122 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ The [`accelerate`](./accelerate) folder contains examples of projects using [Pri
122122

123123
The projects in the [`deployment-platforms`](./deployment-platforms) directory show what "Prisma Client"-based deployment setups look like for various deployment providers. Learn more about [deployment](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/deployment) in the Prisma documentation.
124124

125+
| Demo | Description |
126+
| ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
127+
| [`prisma-compute/hono`](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/prisma-compute/hono) | [Hono](https://hono.dev/) API deployed to Prisma Compute with `@prisma/cli`. |
128+
| [`prisma-compute/nextjs`](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/prisma-compute/nextjs) | [Next.js](https://nextjs.org/) App Router app using standalone output for Prisma Compute. |
129+
| [`prisma-compute/tanstack-start`](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/prisma-compute/tanstack-start) | [TanStack Start](https://tanstack.com/start) app using the Nitro output supported by Prisma Compute. |
130+
125131
## Real-world & production-ready example projects with Prisma
126132

127133
- [Inbox Zero](https://github.com/elie222/inbox-zero): Open source email management tools to reach inbox zero fast

deployment-platforms/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
The projects in this directory show what "Prisma Client"-based deployment setups look like for various deployment providers. Learn more about [deployment](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/deployment) in the Prisma documentation.
44

5+
## Prisma Compute
6+
7+
| Demo | Description |
8+
| --- | --- |
9+
| [`prisma-compute/hono`](./prisma-compute/hono) | Hono API deployed to Prisma Compute with `@prisma/cli`. |
10+
| [`prisma-compute/nextjs`](./prisma-compute/nextjs) | Next.js App Router app using standalone output for Prisma Compute. |
11+
| [`prisma-compute/tanstack-start`](./prisma-compute/tanstack-start) | TanStack Start app using the Nitro output supported by Prisma Compute. |
12+
513
## Additional resources
614

715
- Check out the [Prisma docs](https://www.prisma.io/docs)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Prisma Compute examples
2+
3+
These examples show Prisma ORM apps deployed to Prisma Compute with the
4+
latest `@prisma/cli`.
5+
6+
| Example | Description |
7+
| --- | --- |
8+
| [`hono`](./hono) | Hono API on Node.js. |
9+
| [`nextjs`](./nextjs) | Next.js App Router app using standalone output for Prisma Compute. |
10+
| [`tanstack-start`](./tanstack-start) | TanStack Start app using the Nitro Vite plugin output supported by Prisma Compute. |
11+
12+
Each example includes Prisma ORM, a PostgreSQL schema, seed data, and scripts for
13+
local development and Prisma Compute deployment.
14+
15+
The Compute scripts call `npx @prisma/cli@latest` directly, so the examples do
16+
not pin or install the Prisma CLI.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=require"
2+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
dist
3+
.env
4+
.prisma
5+
prisma/migrations
6+
src/generated/prisma
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Prisma Compute Hono example
2+
3+
This is a small Hono API that uses Prisma ORM with PostgreSQL and deploys to
4+
Prisma Compute with the latest `@prisma/cli`.
5+
6+
## Run locally
7+
8+
```bash
9+
npm install
10+
cp .env.example .env
11+
12+
# Authenticate once, then create a Prisma Postgres database.
13+
npm run compute:login
14+
npm run compute:database:create
15+
16+
# Copy the printed DATABASE_URL into .env.
17+
18+
npm run db:generate
19+
npm run db:migrate -- --name init
20+
npm run db:seed
21+
npm run dev
22+
```
23+
24+
Open [http://localhost:8080](http://localhost:8080). The JSON endpoint is
25+
available at [http://localhost:8080/api/users](http://localhost:8080/api/users).
26+
27+
## Deploy to Prisma Compute
28+
29+
Deploy the app. The script passes `.env` to Prisma Compute, so the deployed app
30+
uses the same seeded database.
31+
32+
```bash
33+
npm run compute:deploy
34+
```
35+
36+
After a successful deploy, inspect the app with:
37+
38+
```bash
39+
npm run compute:open
40+
npm run compute:logs
41+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "prisma-compute-hono",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "tsx watch src/index.ts",
7+
"build": "tsc",
8+
"start": "node dist/index.js",
9+
"db:generate": "prisma generate",
10+
"db:migrate": "prisma migrate dev",
11+
"db:seed": "prisma db seed",
12+
"compute:login": "npx @prisma/cli@latest auth login",
13+
"compute:database:create": "npx @prisma/cli@latest database create prisma-compute-hono --branch main",
14+
"compute:deploy": "npx @prisma/cli@latest app deploy --env .env",
15+
"compute:open": "npx @prisma/cli@latest app open",
16+
"compute:logs": "npx @prisma/cli@latest app logs"
17+
},
18+
"dependencies": {
19+
"@hono/node-server": "2.0.4",
20+
"@prisma/adapter-pg": "7.8.0",
21+
"@prisma/client": "7.8.0",
22+
"dotenv": "17.4.2",
23+
"hono": "4.12.23",
24+
"pg": "8.21.0"
25+
},
26+
"devDependencies": {
27+
"@types/node": "24.12.4",
28+
"@types/pg": "8.20.0",
29+
"prisma": "7.8.0",
30+
"tsx": "4.22.4",
31+
"typescript": "5.9.3"
32+
}
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "dotenv/config";
2+
import { defineConfig, env } from "prisma/config";
3+
4+
export default defineConfig({
5+
schema: "prisma/schema.prisma",
6+
migrations: {
7+
path: "prisma/migrations",
8+
seed: "tsx prisma/seed.ts",
9+
},
10+
datasource: {
11+
url: env("DATABASE_URL"),
12+
},
13+
});
14+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
generator client {
2+
provider = "prisma-client"
3+
output = "../src/generated/prisma"
4+
}
5+
6+
datasource db {
7+
provider = "postgresql"
8+
}
9+
10+
model User {
11+
id Int @id @default(autoincrement())
12+
email String @unique
13+
username String? @unique
14+
name String?
15+
posts Post[]
16+
createdAt DateTime @default(now())
17+
updatedAt DateTime @updatedAt
18+
}
19+
20+
model Post {
21+
id Int @id @default(autoincrement())
22+
title String
23+
content String?
24+
published Boolean @default(false)
25+
authorId Int
26+
author User @relation(fields: [authorId], references: [id])
27+
createdAt DateTime @default(now())
28+
updatedAt DateTime @updatedAt
29+
}
30+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import "dotenv/config";
2+
import { PrismaPg } from "@prisma/adapter-pg";
3+
import { PrismaClient } from "../src/generated/prisma/client.js";
4+
5+
const databaseUrl = process.env.DATABASE_URL;
6+
7+
if (!databaseUrl) {
8+
throw new Error("DATABASE_URL is required");
9+
}
10+
11+
const adapter = new PrismaPg({ connectionString: databaseUrl });
12+
const prisma = new PrismaClient({ adapter });
13+
14+
async function main() {
15+
await prisma.user.upsert({
16+
where: { email: "alice@prisma.io" },
17+
update: {},
18+
create: {
19+
email: "alice@prisma.io",
20+
username: "alice",
21+
name: "Alice",
22+
posts: {
23+
create: [
24+
{
25+
title: "Hello from Hono on Prisma Compute",
26+
content: "This post was inserted by prisma/seed.ts.",
27+
published: true,
28+
},
29+
],
30+
},
31+
},
32+
});
33+
34+
await prisma.user.upsert({
35+
where: { email: "marie@prisma.io" },
36+
update: {},
37+
create: {
38+
email: "marie@prisma.io",
39+
username: "marie",
40+
name: "Marie",
41+
posts: {
42+
create: [
43+
{
44+
title: "Deploy with @prisma/cli",
45+
content: "Run npm run compute:deploy after setting DATABASE_URL in .env.",
46+
published: true,
47+
},
48+
],
49+
},
50+
},
51+
});
52+
}
53+
54+
main()
55+
.then(async () => {
56+
await prisma.$disconnect();
57+
})
58+
.catch(async (error) => {
59+
console.error(error);
60+
await prisma.$disconnect();
61+
process.exit(1);
62+
});

0 commit comments

Comments
 (0)