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

Function probeSchema

src/directory.ts:219–234  ·  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

217 * second connection opened and closed here leaves the first one's locks alone.
218 */
219function probeSchema(dbPath: string): 'schema' | 'no-schema' | 'not-sqlite' | 'unknown' {
220 let db: any = null;
221 try {
222 // A runtime without node:sqlite can't inspect the file: `unknown`, so the
223 // command goes on to open it and reports why that is impossible.
224 const { DatabaseSync } = loadNodeSqlite();
225 db = new DatabaseSync(dbPath, { readOnly: true });
226 const row = db.prepare("SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'nodes'").get();
227 return row !== undefined ? 'schema' : 'no-schema';
228 } catch (error) {
229 return (error as { errcode?: number })?.errcode === SQLITE_NOTADB ? 'not-sqlite' : 'unknown';
230 } finally {
231 // Never hold the handle: Windows file locking would block the owner.
232 try { db?.close(); } catch { /* already closed */ }
233 }
234}
235
236/**
237 * Find the nearest parent directory containing .codegraph/

Callers 3

hasSchemalessDbFunction · 0.85
hasForeignDbFileFunction · 0.85
hasCodeGraphSchemaFunction · 0.85

Calls 4

loadNodeSqliteFunction · 0.90
getMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected