|
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"; |
5 | 5 |
|
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; |
22 | 19 |
|
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; |
26 | 28 |
|
27 | | -// export type Registry = typeof registry; |
| 29 | +export const registry = setup({ |
| 30 | + use: { counter }, |
| 31 | +}); |
| 32 | + |
| 33 | +export type Registry = typeof registry; |
0 commit comments