Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SqlStatementCounter.integration.ts

22 lines668 Bytes

1import * as Tracer from "effect/Tracer";
2​
3export interface SqlStatementCounter {
4 readonly tracer: Tracer.Tracer;
5 readonly count: () => number;
6}
7​
8/**
9 * Install the same counter on every runtime under test, otherwise statements
10 * run by background reactors and statements run by request handlers land in
11 * different counters.
12 */
13export function makeSqlStatementCounter(): SqlStatementCounter {
14 let statements = 0;
15 const tracer = Tracer.make({
16 span: (options) => {
17 if (options.kind === "client" && options.name === "sqlite") statements += 1;
18 return new Tracer.NativeSpan(options);
19 },
20 });
21 return { tracer, count: () => statements };