Skip to content

Commit eb378c1

Browse files
committed
feat(examples): add drizzle example
1 parent 0ac4009 commit eb378c1

File tree

10 files changed

+70
-84
lines changed

10 files changed

+70
-84
lines changed

examples/drizzle/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Hono Integration for RivetKit
1+
# Drizzle Integration for RivetKit
22

3-
Example project demonstrating Hono web framework integration with [RivetKit](https://rivetkit.org).
3+
Example project demonstrating Drizzle ORM integration with [RivetKit](https://rivetkit.org).
44

55
[Learn More →](https://github.com/rivet-gg/rivetkit)
66

@@ -16,18 +16,16 @@ Example project demonstrating Hono web framework integration with [RivetKit](htt
1616

1717
```sh
1818
git clone https://github.com/rivet-gg/rivetkit
19-
cd rivetkit/examples/hono
20-
npm install
19+
cd rivetkit/examples/drizzle
20+
pnpm install
2121
```
2222

2323
### Development
24-
2524
```sh
26-
npm run dev
25+
pnpm run dev
2726
```
28-
29-
Open your browser to http://localhost:3000 to see the Hono server with RivetKit integration.
27+
Open your browser to https://studio.rivet.gg/ to see your RivetKit server.
3028

3129
## License
3230

33-
Apache 2.0
31+
Apache 2.0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE `messages_table` (
2+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3+
`sender` text NOT NULL,
4+
`text` text NOT NULL,
5+
`timestamp` integer NOT NULL
6+
);

examples/drizzle/drizzle/0000_wonderful_iron_patriot.sql

Lines changed: 0 additions & 8 deletions
This file was deleted.

examples/drizzle/drizzle/meta/0000_snapshot.json

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"version": "6",
33
"dialect": "sqlite",
4-
"id": "22f3d49c-97d5-46ca-b0f1-99950c3efec7",
4+
"id": "cb13fd0c-ec74-4b9d-b939-8ad091b0dca1",
55
"prevId": "00000000-0000-0000-0000-000000000000",
66
"tables": {
7-
"users_table": {
8-
"name": "users_table",
7+
"messages_table": {
8+
"name": "messages_table",
99
"columns": {
1010
"id": {
1111
"name": "id",
@@ -14,35 +14,29 @@
1414
"notNull": true,
1515
"autoincrement": true
1616
},
17-
"name": {
18-
"name": "name",
17+
"sender": {
18+
"name": "sender",
1919
"type": "text",
2020
"primaryKey": false,
2121
"notNull": true,
2222
"autoincrement": false
2323
},
24-
"age": {
25-
"name": "age",
26-
"type": "integer",
24+
"text": {
25+
"name": "text",
26+
"type": "text",
2727
"primaryKey": false,
2828
"notNull": true,
2929
"autoincrement": false
3030
},
31-
"email": {
32-
"name": "email",
33-
"type": "text",
31+
"timestamp": {
32+
"name": "timestamp",
33+
"type": "integer",
3434
"primaryKey": false,
3535
"notNull": true,
3636
"autoincrement": false
3737
}
3838
},
39-
"indexes": {
40-
"users_table_email_unique": {
41-
"name": "users_table_email_unique",
42-
"columns": ["email"],
43-
"isUnique": true
44-
}
45-
},
39+
"indexes": {},
4640
"foreignKeys": {},
4741
"compositePrimaryKeys": {},
4842
"uniqueConstraints": {},

examples/drizzle/drizzle/meta/_journal.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@
55
{
66
"idx": 0,
77
"version": "6",
8-
"when": 1750711614205,
9-
"tag": "0000_wonderful_iron_patriot",
10-
"breakpoints": true
11-
},
12-
{
13-
"idx": 1,
14-
"version": "6",
15-
"when": 1750716663518,
16-
"tag": "0001_rich_susan_delgado",
8+
"when": 1755196233006,
9+
"tag": "0000_flippant_bloodstrike",
1710
"breakpoints": true
1811
}
1912
]

examples/drizzle/drizzle/migrations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import m0000 from "./0000_wonderful_iron_patriot.sql";
1+
import m0000 from "./0000_flippant_bloodstrike.sql";
22
import journal from "./meta/_journal.json";
33

44
export default {

examples/drizzle/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "tsx --watch src/server.ts",
7+
"dev": "tsx --loader @rivetkit/sql-loader --watch src/server.ts",
88
"check-types": "tsc --noEmit"
99
},
1010
"devDependencies": {
1111
"@types/node": "^22.13.9",
12-
"rivetkit": "workspace:*",
12+
"@rivetkit/sql-loader": "workspace:*",
1313
"tsx": "^3.12.7",
1414
"typescript": "^5.5.2"
1515
},
1616
"dependencies": {
1717
"@rivetkit/db": "workspace:*",
18+
"@rivetkit/actor": "workspace:*",
1819
"drizzle-kit": "^0.31.2",
1920
"drizzle-orm": "^0.44.2"
2021
},

examples/drizzle/src/db/schema.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// import { int, sqliteTable, text } from "@rivetkit/db/drizzle";
1+
import { int, sqliteTable, text } from "@rivetkit/db/drizzle";
22

3-
// export const usersTable = sqliteTable("users_table", {
4-
// id: int().primaryKey({ autoIncrement: true }),
5-
// name: text().notNull(),
6-
// age: int().notNull(),
7-
// email: text().notNull().unique(),
8-
// email2: text().notNull().unique(),
9-
// });
3+
export const messagesTable = sqliteTable("messages_table", {
4+
id: int().primaryKey({ autoIncrement: true }),
5+
sender: text().notNull(),
6+
text: text().notNull(),
7+
timestamp: int().notNull(),
8+
});

examples/drizzle/src/registry.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
// import { actor, setup } from "rivetkit";
2-
// import { db } from "@rivetkit/db/drizzle";
3-
// import * as schema from "./db/schema";
4-
// import migrations from "../drizzle/migrations";
1+
import { actor, setup } from "@rivetkit/actor";
2+
import { db } from "@rivetkit/db/drizzle";
3+
import { desc } from "drizzle-orm";
4+
import migrations from "../drizzle/migrations";
5+
import * as schema from "./db/schema";
56

6-
// export const counter = actor({
7-
// db: db({ schema, migrations }),
8-
// state: {
9-
// count: 0,
10-
// },
11-
// onAuth: () => {
12-
// // Configure auth here
13-
// },
14-
// actions: {
15-
// increment: (c, x: number) => {
16-
// // createState or state fix fix fix
17-
// c.db.c.state.count += x;
18-
// return c.state.count;
19-
// },
20-
// },
21-
// });
7+
export const counter = actor({
8+
db: db({ schema, migrations }),
9+
onAuth: () => {},
10+
actions: {
11+
// Callable functions from clients: https://rivet.gg/docs/actors/actions
12+
sendMessage: (c, sender: string, text: string) => {
13+
const message = { sender, text, timestamp: Date.now() };
14+
// State changes are automatically persisted
15+
c.db.insert(schema.messagesTable).values(message);
16+
// Send events to all connected clients: https://rivet.gg/docs/actors/events
17+
c.broadcast("newMessage", message);
18+
return message;
19+
},
2220

23-
// export const registry = setup({
24-
// use: { counter },
25-
// });
21+
getHistory: (c) =>
22+
c.db
23+
.select()
24+
.from(schema.messagesTable)
25+
.orderBy(desc(schema.messagesTable.timestamp))
26+
.limit(100),
27+
},
28+
});
29+
30+
export const registry = setup({
31+
use: { counter },
32+
});

examples/drizzle/src/server.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// import { registry } from "./registry";
2-
// import { createMemoryDriver } from "@rivetkit/memory";
3-
// import { serve } from "@rivetkit/nodejs";
1+
import { registry } from "./registry";
42

5-
// serve(registry, {
6-
// driver: createMemoryDriver(),
7-
// });
3+
registry.runServer();

0 commit comments

Comments
 (0)