Refactor path management: Migrate path discovery logic to shared paths module
- Removed `path-discovery.ts` service and replaced its usage with a new `paths.ts` module. - Updated all commands and services to utilize the new path constants and helper functions. - Ensured all necessary directories are created using the new utility functions. - Improved code readability and maintainability by centralizing path configurations.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Database as BunDatabase } from 'bun:sqlite';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { PathDiscovery } from '../path-discovery.js';
|
||||
import { DATA_DIR, DB_PATH, ensureDir } from '../../shared/paths.js';
|
||||
|
||||
// Type alias for better-sqlite3 compatibility
|
||||
type Database = BunDatabase;
|
||||
@@ -47,11 +45,9 @@ export class DatabaseManager {
|
||||
}
|
||||
|
||||
// Ensure the data directory exists
|
||||
const dataDir = PathDiscovery.getInstance().getDataDirectory();
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
ensureDir(DATA_DIR);
|
||||
|
||||
const dbPath = path.join(dataDir, 'claude-mem.db');
|
||||
this.db = new BunDatabase(dbPath, { create: true, readwrite: true });
|
||||
this.db = new BunDatabase(DB_PATH, { create: true, readwrite: true });
|
||||
|
||||
// Apply optimized SQLite settings
|
||||
this.db.run('PRAGMA journal_mode = WAL');
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Database } from 'bun:sqlite';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { PathDiscovery } from '../path-discovery.js';
|
||||
import { DATA_DIR, DB_PATH, ensureDir } from '../../shared/paths.js';
|
||||
|
||||
/**
|
||||
* Lightweight database interface for hooks
|
||||
@@ -12,11 +10,8 @@ export class HooksDatabase {
|
||||
private db: Database;
|
||||
|
||||
constructor() {
|
||||
const dataDir = PathDiscovery.getInstance().getDataDirectory();
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
|
||||
const dbPath = path.join(dataDir, 'claude-mem.db');
|
||||
this.db = new Database(dbPath, { create: true, readwrite: true });
|
||||
ensureDir(DATA_DIR);
|
||||
this.db = new Database(DB_PATH, { create: true, readwrite: true });
|
||||
|
||||
// Ensure optimized settings
|
||||
this.db.run('PRAGMA journal_mode = WAL');
|
||||
|
||||
Reference in New Issue
Block a user