UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

25 lines (24 loc) 780 B
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; }