The catalog counts the rows that SQLite reads and writes for it
Jonas Templestein, 2026-11-26 22:47 UTC · f4b4eff8a302af46d6754f8ccbdd1f635c325070 · parent b942a1a
2 files changed
M core/itx/src/context/reactive-catalog.ts
@@ -408,6 +408,10 @@ counters = { statements: 0, + /** Rows that SQLite read and wrote for those statements, index entries too: what a Durable + * Object is billed by. */ + rowsRead: 0, + rowsWritten: 0, writes: 0, /** Writes of a row equal to the stored one. */ sameWrites: 0, @@ -513,7 +517,11 @@ #exec<T extends Record<string, SqlStorageValue>>(sql: string, ...args: unknown[]): T[] { this.counters.statements += 1; - return this.#sql.exec<T>(sql, ...args).toArray(); + const cursor = this.#sql.exec<T>(sql, ...args); + const rows = cursor.toArray(); + this.counters.rowsRead += cursor.rowsRead || 0; + this.counters.rowsWritten += cursor.rowsWritten || 0; + return rows; } /** Memory that no longer matches SQLite (a transaction that threw) is read again. */
M core/lib/src/api.ts
@@ -1930,8 +1930,9 @@ rev: number; watchers: number; }[]; - /** What the catalog did since it last woke: writes, the writes that changed no window, seeks, - * messages and characters sent. */ + /** What the catalog did since it last woke: statements with the rows that SQLite read and + * wrote for them (what the object is billed by), writes, the writes that changed no window, + * seeks, messages and characters sent. */ counters: Record<string, number>; /** With `{ verify: true }`: each window whose stored size or bound disagrees with the rows. */ faults?: string[];