repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import Database from "better-sqlite3"; |
| #2 | import { HistoryManager } from "./base"; |
| #3 | |
| #4 | export class SQLiteManager implements HistoryManager { |
| #5 | private db: Database.Database; |
| #6 | private stmtInsert!: Database.Statement; |
| #7 | private stmtSelect!: Database.Statement; |
| #8 | |
| #9 | constructor(dbPath: string) { |
| #10 | this.db = new Database(dbPath); |
| #11 | this.init(); |
| #12 | } |
| #13 | |
| #14 | private init(): void { |
| #15 | this.db.exec(` |
| #16 | CREATE TABLE IF NOT EXISTS memory_history ( |
| #17 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| #18 | memory_id TEXT NOT NULL, |
| #19 | previous_value TEXT, |
| #20 | new_value TEXT, |
| #21 | action TEXT NOT NULL, |
| #22 | created_at TEXT, |
| #23 | updated_at TEXT, |
| #24 | is_deleted INTEGER DEFAULT 0 |
| #25 | ) |
| #26 | `); |
| #27 | this.stmtInsert = this.db.prepare( |
| #28 | `INSERT INTO memory_history |
| #29 | (memory_id, previous_value, new_value, action, created_at, updated_at, is_deleted) |
| #30 | VALUES (?, ?, ?, ?, ?, ?, ?)`, |
| #31 | ); |
| #32 | this.stmtSelect = this.db.prepare( |
| #33 | "SELECT * FROM memory_history WHERE memory_id = ? ORDER BY id DESC", |
| #34 | ); |
| #35 | } |
| #36 | |
| #37 | async addHistory( |
| #38 | memoryId: string, |
| #39 | previousValue: string | null, |
| #40 | newValue: string | null, |
| #41 | action: string, |
| #42 | createdAt?: string, |
| #43 | updatedAt?: string, |
| #44 | isDeleted: number = 0, |
| #45 | ): Promise<void> { |
| #46 | this.stmtInsert.run( |
| #47 | memoryId, |
| #48 | previousValue, |
| #49 | newValue, |
| #50 | action, |
| #51 | createdAt ?? null, |
| #52 | updatedAt ?? null, |
| #53 | isDeleted, |
| #54 | ); |
| #55 | } |
| #56 | |
| #57 | async getHistory(memoryId: string): Promise<any[]> { |
| #58 | return this.stmtSelect.all(memoryId) as any[]; |
| #59 | } |
| #60 | |
| #61 | async reset(): Promise<void> { |
| #62 | this.db.exec("DROP TABLE IF EXISTS memory_history"); |
| #63 | this.init(); |
| #64 | } |
| #65 | |
| #66 | close(): void { |
| #67 | this.db.close(); |
| #68 | } |
| #69 | } |
| #70 |