diff --git a/docs/runtime/sqlite.mdx b/docs/runtime/sqlite.mdx index 48c73106eb4a..3be34b16ea3b 100644 --- a/docs/runtime/sqlite.mdx +++ b/docs/runtime/sqlite.mdx @@ -133,6 +133,25 @@ db.close(true); has no effect after the first. + + When using WAL (Write-Ahead Logging) mode with a file-based database, SQLite creates additional sidecar files: + `-wal` (write-ahead log) and `-shm` (shared memory). The cleanup behavior of these files after calling `.close()` + varies by platform and SQLite configuration: + + - **Linux**: Sidecar files are typically cleaned up after close + - **macOS**: Sidecar files may persist after close due to platform-specific SQLite behavior + - **Windows**: Behavior varies by Windows version and SQLite configuration + + If you need to ensure sidecar files are cleaned up, consider manually removing them after closing the database: + ```ts + import { rmSync } from "node:fs"; + + db.close(); + rmSync("mydb.sqlite-wal"); + rmSync("mydb.sqlite-shm"); + ``` + + ### `using` statement You can use the `using` statement to ensure that a database connection is closed when the `using` block is exited. diff --git a/src/js/node/perf_hooks.ts b/src/js/node/perf_hooks.ts index f5b05ed542fd..2e9eb32cd529 100644 --- a/src/js/node/perf_hooks.ts +++ b/src/js/node/perf_hooks.ts @@ -139,6 +139,35 @@ export default { setResourceTimingBufferSize(_) { return performance.setResourceTimingBufferSize(...arguments); }, + timerify(fn: (...args: unknown[]) => unknown) { + const name = fn.name || "anonymous"; + + return function (...args: unknown[]) { + const start = performance.now(); + try { + const result = fn.apply(this, args); + + // Handle both sync and async functions + if (result && typeof result.then === "function") { + // Async function + return result.then((value: unknown) => { + const end = performance.now(); + performance.measure(`${name}()`, start as unknown as string, end as unknown as string); + return value; + }); + } else { + // Sync function + const end = performance.now(); + performance.measure(`${name}()`, start as unknown as string, end as unknown as string); + return result; + } + } catch (error) { + const end = performance.now(); + performance.measure(`${name}()`, start as unknown as string, end as unknown as string); + throw error; + } + }; + }, timeOrigin: performance.timeOrigin, toJSON(_) { return performance.toJSON(...arguments);