diff --git a/packages/shared/src/nodeSqliteClient.test.ts b/packages/shared/src/nodeSqliteClient.test.ts index 24910bc0bf9cf..023d61ab67800 100644 --- a/packages/shared/src/nodeSqliteClient.test.ts +++ b/packages/shared/src/nodeSqliteClient.test.ts @@ -595,6 +595,18 @@ it.effect("keeps the reader read-only even if a statement turns query_only off", ), ); +it.effect("keeps a reader's sorts and temp tables in memory, not in temp files", () => + withReaderClient((sql) => + Effect.gen(function* () { + const rows = yield* sql<{ temp_store: number }>`PRAGMA temp_store`.pipe( + sql.withTransaction, + SqliteClient.readOnly, + ); + assert.equal(rows[0]?.temp_store, 2); + }), + ), +); + it.effect("keeps read-only work inside a write transaction on the writer", () => withReaderClient((sql) => sql.withTransaction( diff --git a/packages/shared/src/nodeSqliteClient.ts b/packages/shared/src/nodeSqliteClient.ts index da521a7c6036d..1b46015d89f48 100644 --- a/packages/shared/src/nodeSqliteClient.ts +++ b/packages/shared/src/nodeSqliteClient.ts @@ -214,6 +214,8 @@ try { allowExtension: workerData.allowExtension, }); next.exec("PRAGMA busy_timeout = 5000;"); + // Callers set pragmas only on the writer, so a reader would sort and build temp tables in files. + next.exec("PRAGMA temp_store = MEMORY;"); // Reads the header, so a file that is not a database fails here rather than on first use. const mode = String(next.prepare("PRAGMA journal_mode").get().journal_mode).toLowerCase(); // Without WAL a reader's shared lock blocks the writer's commits, so refuse.