Skip to content

Commit 3c13119

Browse files
committed
feat: sqlite support
1 parent d996b39 commit 3c13119

File tree

9 files changed

+5621
-188
lines changed

9 files changed

+5621
-188
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"devDependencies": {
2929
"@biomejs/biome": "^1.9.4",
3030
"@types/ws": "^8.5.14",
31+
"better-sqlite3": "^11.9.1",
3132
"dedent": "^1.5.3",
3233
"lefthook": "^1.6.12",
3334
"turbo": "^2.0.1",

packages/actor-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
"@types/invariant": "^2",
154154
"@types/node": "^22.13.1",
155155
"@types/ws": "^8",
156+
"drizzle-kit": "^0.30.5",
157+
"drizzle-orm": "^0.41.0",
156158
"eventsource": "^3.0.5",
157159
"tsup": "^8.4.0",
158160
"typescript": "^5.7.3",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "drizzle-kit";
2+
3+
export default defineConfig({
4+
out: "./tests/schemas/chat-room/drizzle",
5+
dialect: "sqlite",
6+
schema: "./tests/schemas/chat-room/schema.ts",
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE `messages` (
2+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3+
`username` text,
4+
`message` text
5+
);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"version": "6",
3+
"dialect": "sqlite",
4+
"id": "78d399d7-9b51-4e04-ad31-1c3dc909e24a",
5+
"prevId": "00000000-0000-0000-0000-000000000000",
6+
"tables": {
7+
"messages": {
8+
"name": "messages",
9+
"columns": {
10+
"id": {
11+
"name": "id",
12+
"type": "integer",
13+
"primaryKey": true,
14+
"notNull": true,
15+
"autoincrement": true
16+
},
17+
"username": {
18+
"name": "username",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": false,
22+
"autoincrement": false
23+
},
24+
"message": {
25+
"name": "message",
26+
"type": "text",
27+
"primaryKey": false,
28+
"notNull": false,
29+
"autoincrement": false
30+
}
31+
},
32+
"indexes": {},
33+
"foreignKeys": {},
34+
"compositePrimaryKeys": {},
35+
"uniqueConstraints": {},
36+
"checkConstraints": {}
37+
}
38+
},
39+
"views": {},
40+
"enums": {},
41+
"_meta": {
42+
"schemas": {},
43+
"tables": {},
44+
"columns": {}
45+
},
46+
"internal": {
47+
"indexes": {}
48+
}
49+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "7",
3+
"dialect": "sqlite",
4+
"entries": [
5+
{
6+
"idx": 0,
7+
"version": "6",
8+
"when": 1743016581641,
9+
"tag": "0000_military_elektra",
10+
"breakpoints": true
11+
}
12+
]
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { sqliteTable as table } from "drizzle-orm/sqlite-core";
2+
import * as t from "drizzle-orm/sqlite-core";
3+
4+
export const messages = table("messages", {
5+
id: t.int().primaryKey({ autoIncrement: true }),
6+
username: t.text(),
7+
message: t.text(),
8+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { actor, setup } from "@/mod";
2+
import { describe, test, expect, vi } from "vitest";
3+
import { setupTest } from "@/test/mod";
4+
import { drizzle } from "drizzle-orm/better-sqlite3";
5+
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
6+
import path from "path";
7+
8+
describe("Actor SQLite", () => {
9+
test("simple test", async () => {
10+
// Define actor with static vars
11+
const chatAccotr = actor({
12+
createVars: (c) => ({
13+
drizzle: drizzle(c.sql),
14+
}),
15+
onStart: (c) => {
16+
migrate(c.vars.drizzle, {
17+
migrationsFolder: path.join(
18+
__dirname,
19+
"./schemas/chat-room/drizzle/",
20+
),
21+
});
22+
},
23+
actions: {
24+
getMessages: (c) => {},
25+
createMessage: (c) => {},
26+
},
27+
});
28+
29+
const app = setup({
30+
actors: { varActor },
31+
});
32+
33+
const { client } = await setupTest<typeof app>(app);
34+
const instance = await client.varActor.get();
35+
36+
//// Test accessing vars
37+
//const result = await instance.getVars();
38+
//expect(result).toEqual({ counter: 42, name: "test-actor" });
39+
//
40+
//// Test accessing specific var property
41+
//const name = await instance.getName();
42+
//expect(name).toBe("test-actor");
43+
});
44+
});

0 commit comments

Comments
 (0)