UNPKG

scai

Version:

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

32 lines (31 loc) 1.17 kB
import fs from 'fs'; import path from 'path'; import { SCAI_HOME } from '../constants.js'; import { Config } from '../config.js'; import Database from 'better-sqlite3'; /** * Returns a per-repo SQLite database instance. * Ensures the directory and file are created. */ export function getDbForRepo() { const repoRoot = Config.getIndexDir(); if (!repoRoot) { throw new Error('No index directory set. Please set an index directory first.'); } fs.mkdirSync(SCAI_HOME, { recursive: true }); const dbPath = getDbPathForRepo(); fs.mkdirSync(path.dirname(dbPath), { recursive: true }); const db = new Database(dbPath); db.pragma('journal_mode = WAL'); return db; } export function getDbPathForRepo() { const repoRoot = Config.getIndexDir(); if (!repoRoot) { throw new Error('No index directory set. Please set an index directory first.'); } // Use path.basename to get the repo name from the full path const repoName = path.basename(repoRoot); // Get the last part of the path (the repo name) const scaiRepoPath = path.join(SCAI_HOME, 'repos', repoName, 'db.sqlite'); return scaiRepoPath; }