| 36 | } |
| 37 | |
| 38 | export class SqliteWorkspaceStore implements WorkspaceStore { |
| 39 | private readonly database: DatabaseHandle; |
| 40 | |
| 41 | constructor(stateDir: string) { |
| 42 | this.database = openDatabase(stateDir); |
| 43 | } |
| 44 | |
| 45 | createSession(input: { |
| 46 | id: string; |
| 47 | root: string; |
| 48 | mode?: WorkspaceMode; |
| 49 | sourceRoot?: string; |
| 50 | baseRef?: string; |
| 51 | baseSha?: string; |
| 52 | managed?: boolean; |
| 53 | }): WorkspaceSession { |
| 54 | const now = new Date().toISOString(); |
| 55 | const session: WorkspaceSession = { |
| 56 | id: input.id, |
| 57 | root: input.root, |
| 58 | status: "active", |
| 59 | mode: input.mode ?? "checkout", |
| 60 | sourceRoot: input.sourceRoot, |
| 61 | baseRef: input.baseRef, |
| 62 | baseSha: input.baseSha, |
| 63 | managed: input.managed ?? false, |
| 64 | createdAt: now, |
| 65 | lastUsedAt: now, |
| 66 | }; |
| 67 | |
| 68 | this.database.db |
| 69 | .insert(workspaceSessions) |
| 70 | .values({ |
| 71 | id: session.id, |
| 72 | root: session.root, |
| 73 | status: session.status, |
| 74 | mode: session.mode, |
| 75 | sourceRoot: session.sourceRoot ?? null, |
| 76 | baseRef: session.baseRef ?? null, |
| 77 | baseSha: session.baseSha ?? null, |
| 78 | managed: String(session.managed), |
| 79 | createdAt: session.createdAt, |
| 80 | lastUsedAt: session.lastUsedAt, |
| 81 | }) |
| 82 | .run(); |
| 83 | |
| 84 | return session; |
| 85 | } |
| 86 | |
| 87 | getSession(id: string): WorkspaceSession | undefined { |
| 88 | const row = this.database.db |
| 89 | .select() |
| 90 | .from(workspaceSessions) |
| 91 | .where(eq(workspaceSessions.id, id)) |
| 92 | .get(); |
| 93 | |
| 94 | return row ? rowToWorkspaceSession(row) : undefined; |
| 95 | } |
nothing calls this directly
no outgoing calls
no test coverage detected