Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions script/node-polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ class NodeDatabasePolyfill {
close(): void {
this.db.close();
}

/**
* Wraps a function in a transaction. Returns a callable that executes
* the function within BEGIN/COMMIT, with ROLLBACK on error.
* Matches Bun's db.transaction() API.
*/
transaction<T>(fn: () => T): () => T {
return () => {
this.db.exec("BEGIN");
try {
const result = fn();
this.db.exec("COMMIT");
return result;
} catch (error) {
this.db.exec("ROLLBACK");
throw error;
}
};
}
}

const bunSqlitePolyfill = { Database: NodeDatabasePolyfill };
Expand Down
Loading