MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / probeSchema

Function probeSchema

src/directory.ts:216–230  ·  view source on GitHub ↗

* What `codegraph.db` holds, asked of SQLite itself through a read-only * connection: the codegraph schema, a database without it, not a database at * all (SQLITE_NOTADB), or `unknown` — locked, busy, a WAL db in a directory we * cannot create `-shm` in (read-only checkout, mount, another user's

(dbPath: string)

Source from the content-addressed store, hash-verified

214 * second connection opened and closed here leaves the first one's locks alone.
215 */
216function probeSchema(dbPath: string): 'schema' | 'no-schema' | 'not-sqlite' | 'unknown' {
217 // eslint-disable-next-line @typescript-eslint/no-require-imports
218 const { DatabaseSync } = require('node:sqlite');
219 let db: any = null;
220 try {
221 db = new DatabaseSync(dbPath, { readOnly: true });
222 const row = db.prepare("SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'nodes'").get();
223 return row !== undefined ? 'schema' : 'no-schema';
224 } catch (error) {
225 return (error as { errcode?: number })?.errcode === SQLITE_NOTADB ? 'not-sqlite' : 'unknown';
226 } finally {
227 // Never hold the handle: Windows file locking would block the owner.
228 try { db?.close(); } catch { /* already closed */ }
229 }
230}
231
232/**
233 * Find the nearest parent directory containing .codegraph/

Callers 3

hasSchemalessDbFunction · 0.85
hasForeignDbFileFunction · 0.85
hasCodeGraphSchemaFunction · 0.85

Calls 3

getMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected