tana-mcp-codemode 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,13 +8,13 @@
8
8
  * Configure database location via TANA_HISTORY_PATH env var.
9
9
  */
10
10
 
11
- import { Database } from "bun:sqlite";
11
+ import { createDatabase, type CompatDatabase } from "../compat";
12
12
  import { homedir } from "os";
13
13
  import { join, dirname } from "path";
14
14
  import { mkdirSync, existsSync } from "fs";
15
15
  import type { ScriptRun } from "../types";
16
16
 
17
- let db: Database | null = null;
17
+ let db: CompatDatabase | null = null;
18
18
 
19
19
  function getDbPath(): string {
20
20
  // Allow custom path via env var
@@ -46,7 +46,7 @@ function getDbPath(): string {
46
46
  return join(baseDir, "history.db");
47
47
  }
48
48
 
49
- function migrateDb(database: Database): void {
49
+ function migrateDb(database: CompatDatabase): void {
50
50
  // Get existing columns
51
51
  const columns = database
52
52
  .prepare("PRAGMA table_info(script_runs)")
@@ -63,18 +63,18 @@ function migrateDb(database: Database): void {
63
63
 
64
64
  for (const col of newColumns) {
65
65
  if (!columnNames.has(col.name)) {
66
- database.run(`ALTER TABLE script_runs ADD COLUMN ${col.name} ${col.type}`);
66
+ database.exec(`ALTER TABLE script_runs ADD COLUMN ${col.name} ${col.type}`);
67
67
  }
68
68
  }
69
69
  }
70
70
 
71
- export function initDb(): Database {
71
+ export function initDb(): CompatDatabase {
72
72
  if (db) return db;
73
73
 
74
74
  const dbPath = getDbPath();
75
- db = new Database(dbPath, { create: true });
75
+ db = createDatabase(dbPath);
76
76
 
77
- db.run(`
77
+ db.exec(`
78
78
  CREATE TABLE IF NOT EXISTS script_runs (
79
79
  id INTEGER PRIMARY KEY AUTOINCREMENT,
80
80
  timestamp INTEGER NOT NULL,
@@ -94,22 +94,22 @@ export function initDb(): Database {
94
94
  // Migrate existing databases
95
95
  migrateDb(db);
96
96
 
97
- db.run(`
97
+ db.exec(`
98
98
  CREATE INDEX IF NOT EXISTS idx_script_runs_timestamp
99
99
  ON script_runs(timestamp DESC)
100
100
  `);
101
101
 
102
- db.run(`
102
+ db.exec(`
103
103
  CREATE INDEX IF NOT EXISTS idx_script_runs_session
104
104
  ON script_runs(session_id)
105
105
  `);
106
106
 
107
- db.run(`
107
+ db.exec(`
108
108
  CREATE INDEX IF NOT EXISTS idx_script_runs_workspace
109
109
  ON script_runs(workspace_id)
110
110
  `);
111
111
 
112
- return db;
112
+ return db!;
113
113
  }
114
114
 
115
115
  export interface SaveScriptRunOptions {