Skip to content

Commit caab5fa

Browse files
authored
Add honc-the-halls example (#49)
* Add honc the halls example app * Update readme
1 parent e29219a commit caab5fa

16 files changed

+1183
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DATABASE_URL=...
2+
TOGETHER_AI_API_KEY=...

examples/honc-the-halls/.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# prod
2+
dist/
3+
4+
# dev
5+
.yarn/
6+
!.yarn/releases
7+
.vscode/*
8+
!.vscode/launch.json
9+
!.vscode/*.code-snippets
10+
.idea/workspace.xml
11+
.idea/usage.statistics.xml
12+
.idea/shelf
13+
14+
# deps
15+
node_modules/
16+
.wrangler
17+
18+
# env
19+
.env
20+
.env.production
21+
.dev.vars
22+
23+
# logs
24+
logs/
25+
*.log
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
pnpm-debug.log*
30+
lerna-debug.log*
31+
32+
# misc
33+
.DS_Store
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
## 🪿 HONC
2+
3+
This is a project created with the `create-honc-app` template.
4+
5+
Learn more about the HONC stack on the [website](https://honc.dev) or the main [repo](https://github.com/fiberplane/create-honc-app).
6+
7+
### Getting started
8+
9+
Make sure you have Neon set up and configured with your database. Create a .dev.vars file with the `DATABASE_URL` key and value (see: `.dev.vars.example`).
10+
11+
### Project structure
12+
13+
```#
14+
├── src
15+
│ ├── index.ts # Hono app entry point
16+
│ └── db
17+
│ └── schema.ts # Database schema
18+
├── seed.ts # Optional seeding script
19+
├── .dev.vars.example # Example .dev.vars file
20+
├── wrangler.toml # Cloudflare Workers configuration
21+
├── drizzle.config.ts # Drizzle configuration
22+
├── tsconfig.json # TypeScript configuration
23+
└── package.json
24+
```
25+
26+
### Commands
27+
28+
Run the migrations and (optionally) seed the database:
29+
30+
```sh
31+
# this is a convenience script that runs db:generate, db:migrate, and db:seed
32+
npm run db:setup
33+
```
34+
35+
Run the development server:
36+
37+
```sh
38+
npm run dev
39+
```
40+
41+
### Developing
42+
43+
When you iterate on the database schema, you'll need to generate a new migration and apply it:
44+
45+
```sh
46+
npm run db:generate
47+
npm run db:migrate
48+
```
49+
50+
### Deploying
51+
52+
Set your `DATABASE_URL` secret (and any other secrets you need) with wrangler:
53+
54+
```sh
55+
npx wrangler secret put DATABASE_URL
56+
```
57+
58+
Finally, change the name of the project in `wrangler.toml` to something appropriate for your project
59+
60+
```toml
61+
name = "my-neon-project"
62+
```
63+
64+
Deploy with wrangler:
65+
66+
```sh
67+
npm run deploy
68+
```

examples/honc-the-halls/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 🪿 HONC The Halls
2+
3+
A Made-for-TV Christmas Movie idea generator.
4+
5+
**See it live: https://honc-the-halls.fp.dev**
6+
7+
> This is a project created with a `create-honc-app` template.
8+
> For the original README that describes the HONC stack, see [README-honc.md](./README-honc.md)
9+
10+
Learn more about the HONC stack on the [website](https://honc.dev) or the main [repo](https://github.com/fiberplane/create-honc-app).
11+
12+
13+
### Deploying
14+
15+
Set the following secrets:
16+
17+
- `DATABASE_URL`
18+
- `TOGETHER_API_KEY`
19+
20+
```sh
21+
npx wrangler secret put DATABASE_URL
22+
npx wrangler secret put TOGETHER_API_KEY
23+
```
24+
25+
Deploy with wrangler:
26+
27+
```sh
28+
npm run deploy
29+
```
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { config } from "dotenv";
2+
import { defineConfig } from "drizzle-kit";
3+
4+
config({ path: "./.dev.vars" });
5+
6+
export default defineConfig({
7+
schema: "./src/db/schema.ts",
8+
out: "./drizzle",
9+
dialect: "postgresql",
10+
dbCredentials: {
11+
url: process.env.DATABASE_URL ?? "",
12+
},
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE IF NOT EXISTS "movie_ideas" (
2+
"id" serial PRIMARY KEY NOT NULL,
3+
"prompt" text,
4+
"response" text,
5+
"created_at" timestamp DEFAULT now() NOT NULL,
6+
"updated_at" timestamp DEFAULT now() NOT NULL
7+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"id": "a4450dd7-5fc2-4f73-bd52-f5a54074c99c",
3+
"prevId": "00000000-0000-0000-0000-000000000000",
4+
"version": "7",
5+
"dialect": "postgresql",
6+
"tables": {
7+
"public.movie_ideas": {
8+
"name": "movie_ideas",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "serial",
14+
"primaryKey": true,
15+
"notNull": true
16+
},
17+
"prompt": {
18+
"name": "prompt",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": false
22+
},
23+
"response": {
24+
"name": "response",
25+
"type": "text",
26+
"primaryKey": false,
27+
"notNull": false
28+
},
29+
"created_at": {
30+
"name": "created_at",
31+
"type": "timestamp",
32+
"primaryKey": false,
33+
"notNull": true,
34+
"default": "now()"
35+
},
36+
"updated_at": {
37+
"name": "updated_at",
38+
"type": "timestamp",
39+
"primaryKey": false,
40+
"notNull": true,
41+
"default": "now()"
42+
}
43+
},
44+
"indexes": {},
45+
"foreignKeys": {},
46+
"compositePrimaryKeys": {},
47+
"uniqueConstraints": {},
48+
"policies": {},
49+
"checkConstraints": {},
50+
"isRLSEnabled": false
51+
}
52+
},
53+
"enums": {},
54+
"schemas": {},
55+
"sequences": {},
56+
"roles": {},
57+
"policies": {},
58+
"views": {},
59+
"_meta": {
60+
"columns": {},
61+
"schemas": {},
62+
"tables": {}
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "7",
3+
"dialect": "postgresql",
4+
"entries": [
5+
{
6+
"idx": 0,
7+
"version": "7",
8+
"when": 1735086837055,
9+
"tag": "0000_dizzy_gateway",
10+
"breakpoints": true
11+
}
12+
]
13+
}

examples/honc-the-halls/package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "honc-the-halls",
3+
"scripts": {
4+
"dev": "wrangler dev src/index.tsx",
5+
"deploy": "wrangler deploy --minify src/index.tsx",
6+
"db:generate": "drizzle-kit generate",
7+
"db:migrate": "drizzle-kit migrate",
8+
"db:seed": "tsx seed.ts",
9+
"db:setup": "npm run db:generate && npm run db:migrate && npm run db:seed",
10+
"db:studio": "drizzle-kit studio",
11+
"fiberplane": "npx @fiberplane/studio@latest"
12+
},
13+
"dependencies": {
14+
"@neondatabase/serverless": "^0.10.1",
15+
"dotenv": "^16.4.5",
16+
"drizzle-orm": "^0.36.4",
17+
"hono": "^4.6.7",
18+
"together-ai": "^0.10.0"
19+
},
20+
"devDependencies": {
21+
"@cloudflare/workers-types": "^4.20241205.0",
22+
"@fiberplane/hono-otel": "0.8.0-canary.3",
23+
"drizzle-kit": "^0.28.1",
24+
"drizzle-seed": "^0.1.2",
25+
"tsx": "^4.19.2",
26+
"typescript": "^5.5.4",
27+
"wrangler": "^3.95.0"
28+
}
29+
}

examples/honc-the-halls/seed.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { neon } from "@neondatabase/serverless";
2+
import { config } from "dotenv";
3+
import { drizzle } from "drizzle-orm/neon-http";
4+
import * as schema from "./src/db/schema";
5+
import { seed } from "drizzle-seed";
6+
7+
config({ path: ".dev.vars" });
8+
9+
// biome-ignore lint/style/noNonNullAssertion: error from neon client is helpful enough to fix
10+
const sql = neon(process.env.DATABASE_URL!);
11+
const db = drizzle(sql);
12+
13+
async function seedDatabase() {
14+
// Read more about seeding here: https://orm.drizzle.team/docs/seed-overview#drizzle-seed
15+
await seed(db, schema);
16+
}
17+
18+
async function main() {
19+
try {
20+
await seedDatabase();
21+
console.log("✅ Database seeded successfully!");
22+
console.log("🪿 Run `npm run fiberplane` to explore data with your api.");
23+
} catch (error) {
24+
console.error("❌ Error during seeding:", error);
25+
process.exit(1);
26+
} finally {
27+
process.exit(0);
28+
}
29+
}
30+
main();

0 commit comments

Comments
 (0)