scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.
25 lines (24 loc) • 780 B
JavaScript
import fs from 'fs';
import path from 'path';
import { SCAI_HOME } from '../constants.js';
import { readConfig } from '../config.js';
import Database from 'better-sqlite3';
/**
* Returns a per-repo SQLite database instance.
* Ensures the directory and file are created.
*/
export function getDbPathForRepo() {
const cfg = readConfig();
const repoKey = cfg.activeRepo;
if (!repoKey) {
throw new Error('No active repo set. Please set an index directory first.');
}
return path.join(SCAI_HOME, 'repos', repoKey, 'db.sqlite');
}
export function getDbForRepo() {
const dbPath = getDbPathForRepo();
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
const db = new Database(dbPath);
db.pragma('journal_mode = WAL');
return db;
}