Skip to content

Commit 99cb613

Browse files
railway example proejct created
1 parent 7a09f44 commit 99cb613

File tree

8 files changed

+233
-0
lines changed

8 files changed

+233
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
src/generated/prisma
3+
.env
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Railway deployment example
2+
3+
[Deployment guide](https://www.prisma.io/docs/guides/deployment/deploying-to-railway)
4+
5+
## Download manually
6+
7+
```bash
8+
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/deployment-platforms/railway
9+
cd railway
10+
```
11+
12+
## Resources
13+
14+
- Check out the [Prisma docs](https://www.prisma.io/docs)
15+
- [Join our community on Discord](https://pris.ly/discord?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) to share feedback and interact with other users.
16+
- [Subscribe to our YouTube channel](https://pris.ly/youtube?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for live demos and video tutorials.
17+
- [Follow us on X](https://pris.ly/x?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for the latest updates.
18+
- Report issues or ask [questions on GitHub](https://pris.ly/github?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "railway",
3+
"type": "module",
4+
"scripts": {
5+
"dev": "tsx watch src/index.ts",
6+
"start": "tsx src/index.ts"
7+
},
8+
"dependencies": {
9+
"@hono/node-server": "^1.11.2",
10+
"@prisma/client": "^6.15.0",
11+
"dotenv": "^17.2.2",
12+
"hono": "^4.9.6"
13+
},
14+
"devDependencies": {
15+
"@types/node": "^22.10.5",
16+
"prisma": "^6.15.0",
17+
"tsx": "^4.20.5"
18+
}
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- CreateTable
2+
CREATE TABLE "public"."User" (
3+
"email" TEXT NOT NULL,
4+
"id" SERIAL NOT NULL,
5+
"name" TEXT,
6+
7+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "public"."Post" (
12+
"authorId" INTEGER,
13+
"content" TEXT,
14+
"id" SERIAL NOT NULL,
15+
"published" BOOLEAN NOT NULL DEFAULT false,
16+
"title" TEXT NOT NULL,
17+
18+
CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
19+
);
20+
21+
-- CreateIndex
22+
CREATE UNIQUE INDEX "User_email_key" ON "public"."User"("email");
23+
24+
-- AddForeignKey
25+
ALTER TABLE "public"."Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "postgresql"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
generator client {
2+
provider = "prisma-client"
3+
output = "../src/generated/prisma"
4+
}
5+
6+
datasource db {
7+
provider = "postgresql"
8+
url = env("DATABASE_URL")
9+
}
10+
11+
model User {
12+
email String @unique
13+
id Int @id @default(autoincrement())
14+
name String?
15+
posts Post[]
16+
}
17+
18+
model Post {
19+
authorId Int?
20+
content String?
21+
id Int @id @default(autoincrement())
22+
published Boolean @default(false)
23+
title String
24+
author User? @relation(fields: [authorId], references: [id])
25+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import "dotenv/config";
2+
import { Hono } from "hono";
3+
import { PrismaClient } from "./generated/prisma/client";
4+
import { serve } from "@hono/node-server";
5+
6+
const prisma = new PrismaClient();
7+
const app = new Hono();
8+
9+
app.get("/", (c) => {
10+
const html = `
11+
<!DOCTYPE html>
12+
<html>
13+
<head>
14+
<title>Prisma + Railway Example</title>
15+
<style>
16+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
17+
h1 { color: #333; }
18+
.endpoint { margin: 10px 0; padding: 10px; background: #f5f5f5; border-radius: 4px; }
19+
button { margin-left: 10px; padding: 4px 8px; cursor: pointer; }
20+
pre { margin-top: 20px; padding: 10px; border: 1px solid #ddd; background: #f9f9f9; }
21+
</style>
22+
</head>
23+
<body>
24+
<h1>API Endpoints</h1>
25+
26+
<div class="endpoint">
27+
<code>GET /api</code>
28+
<button onclick="testEndpoint('/api')">Test</button>
29+
</div>
30+
31+
<div class="endpoint">
32+
<code>GET /api/feed</code>
33+
<button onclick="testEndpoint('/api/feed')">Test</button>
34+
</div>
35+
36+
<div class="endpoint">
37+
<code>GET /api/seed</code>
38+
<button onclick="testEndpoint('/api/seed')">Test</button>
39+
</div>
40+
41+
<pre><code id="result">Click a button to test an endpoint</code></pre>
42+
43+
<script>
44+
async function testEndpoint(endpoint) {
45+
const resultDiv = document.getElementById('result');
46+
resultDiv.textContent = 'Loading...';
47+
48+
try {
49+
const response = await fetch(endpoint);
50+
const data = await response.json();
51+
resultDiv.textContent = JSON.stringify(data, null, 2);
52+
} catch (error) {
53+
resultDiv.textContent = 'Error: ' + error.message;
54+
}
55+
}
56+
</script>
57+
</body>
58+
</html>
59+
`;
60+
return c.html(html);
61+
});
62+
63+
app.get("/api", async (c) => {
64+
return c.json({ up: true });
65+
});
66+
67+
app.get("/api/seed", async (c) => {
68+
try {
69+
await prisma.post.deleteMany({});
70+
await prisma.user.deleteMany({});
71+
72+
const author1 = await prisma.user.create({
73+
data: {
74+
75+
name: "Jane Doe",
76+
posts: {
77+
create: {
78+
title: "Comparing Database Types",
79+
content:
80+
"https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/",
81+
published: true,
82+
},
83+
},
84+
},
85+
include: { posts: true },
86+
});
87+
88+
const author2 = await prisma.user.create({
89+
data: {
90+
91+
name: "John Smith",
92+
posts: {
93+
create: {
94+
title: "Getting Started with Prisma",
95+
content: "https://www.prisma.io/docs/getting-started",
96+
published: true,
97+
},
98+
},
99+
},
100+
include: { posts: true },
101+
});
102+
103+
return c.json({
104+
message: "Database seeded successfully",
105+
authors: [author1, author2],
106+
});
107+
} catch (e) {
108+
return c.json({ error: "Failed to seed database" }, 500);
109+
}
110+
});
111+
112+
app.get("/api/feed", async (c) => {
113+
const posts = await prisma.post.findMany({
114+
where: { published: true },
115+
include: { author: true },
116+
});
117+
return c.json(posts);
118+
});
119+
120+
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
121+
console.log(`Server is running on port http://localhost:${port}`);
122+
123+
serve({
124+
fetch: app.fetch,
125+
port,
126+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"strict": true,
7+
"skipLibCheck": true,
8+
"lib": [
9+
"ESNext"
10+
],
11+
"jsx": "react-jsx",
12+
"jsxImportSource": "hono/jsx"
13+
},
14+
}

0 commit comments

Comments
 (0)