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

Function countStatements

__tests__/explore-long-query.test.ts:35–45  ·  view source on GitHub ↗

Count the statements run whose SQL matches `pattern`, through the adapter.

(db: SqliteDatabase, pattern: RegExp)

Source from the content-addressed store, hash-verified

33
34/** Count the statements run whose SQL matches `pattern`, through the adapter. */
35function countStatements(db: SqliteDatabase, pattern: RegExp): { count: number } {
36 const counter = { count: 0 };
37 const prepare = db.prepare.bind(db);
38 vi.spyOn(db, 'prepare').mockImplementation((sql: string) => {
39 const stmt = prepare(sql);
40 if (!pattern.test(sql)) return stmt;
41 const wrap = <T extends (...a: any[]) => any>(fn: T): T => ((...args: any[]) => { counter.count++; return fn(...args); }) as T;
42 return { ...stmt, all: wrap(stmt.all.bind(stmt)), get: wrap(stmt.get.bind(stmt)), iterate: wrap(stmt.iterate.bind(stmt)), run: stmt.run.bind(stmt) };
43 });
44 return counter;
45}
46
47const DEF = ['class', 'interface', 'struct', 'union', 'trait', 'protocol', 'enum', 'type_alias'];
48const CALL = ['function', 'method', 'component'];

Callers 1

Calls 3

prepareFunction · 0.85
wrapFunction · 0.85
bindMethod · 0.80

Tested by

no test coverage detected