Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 4c24c71

Browse files
committed
feat: sqlite v2
1 parent ea57692 commit 4c24c71

File tree

29 files changed

+261
-168
lines changed

29 files changed

+261
-168
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,5 @@ Cargo.lock
184184
**/.wrangler
185185
**/.DS_Store
186186
.aider*
187+
188+
packages/**/tsup.config.bundled_*.mjs
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import journal from './meta/_journal.json';
2-
import m0000 from './0000_wonderful_iron_patriot.sql';
1+
import journal from "./meta/_journal.json";
2+
import m0000 from "./0000_wonderful_iron_patriot.sql";
33

4-
export default {
5-
journal,
6-
migrations: {
7-
m0000,
8-
}
9-
}
10-
4+
export default {
5+
journal,
6+
migrations: {
7+
m0000,
8+
},
9+
};

examples/drizzle/hooks.js

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

examples/drizzle/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
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:*",
13+
"@rivetkit/actor": "workspace:*",
1314
"tsx": "^3.12.7",
1415
"typescript": "^5.5.2"
1516
},

examples/drizzle/register.js

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

examples/drizzle/src/db/schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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 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+
});

examples/drizzle/src/registry.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
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 * as schema from "./db/schema";
4+
import migrations from "../drizzle/migrations";
55

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-
// });
6+
export const counter = actor({
7+
db: db({ schema, migrations }),
8+
state: {
9+
count: 0,
10+
},
11+
onAuth: () => {
12+
return "hello";
13+
// Configure auth here
14+
},
15+
actions: {
16+
increment: (c, x: number) => {
17+
// createState or state fix fix fix
18+
const y = c.db;
2219

23-
// export const registry = setup({
24-
// use: { counter },
25-
// });
20+
// Here's DB is unknown
21+
// c.db.usersTable;
22+
return c.state.count;
23+
},
24+
},
25+
});
26+
// but here, the type is known
27+
// (await counter.config.db("hello")).client.query.usersTable.findFirst;
2628

27-
// export type Registry = typeof registry;
29+
export const registry = setup({
30+
use: { counter },
31+
});
32+
33+
export type Registry = typeof registry;

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+
await registry.runServer();

packages/core/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@
135135
"types": "./dist/test/mod.d.cts",
136136
"default": "./dist/test/mod.cjs"
137137
}
138+
},
139+
"./db": {
140+
"import": {
141+
"types": "./dist/db/mod.d.ts",
142+
"default": "./dist/db/mod.js"
143+
},
144+
"require": {
145+
"types": "./dist/db/mod.d.cts",
146+
"default": "./dist/bd/mod.cjs"
147+
}
138148
}
139149
},
140150
"engines": {
@@ -143,7 +153,7 @@
143153
"sideEffects": false,
144154
"scripts": {
145155
"dev": "pnpm build --watch",
146-
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/drivers/rivet/mod.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts",
156+
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/drivers/rivet/mod.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/db/mod.ts",
147157
"check-types": "tsc --noEmit",
148158
"boop": "tsc --outDir dist/test -d",
149159
"test": "vitest run",

packages/core/src/actor/action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { ConnId } from "./connection";
55
import type { ActorContext } from "./context";
66
import type { SaveStateOptions } from "./instance";
77
import type { Schedule } from "./schedule";
8-
import { Registry } from "@/registry/mod";
9-
import { Client } from "@/client/client";
8+
import type { Registry } from "@/registry/mod";
9+
import type { Client } from "@/client/client";
1010

1111
/**
1212
* Context for a remote procedure call.

0 commit comments

Comments
 (0)