fix(types): expose SQLite transaction state (#9848)

Co-authored-by: backryun <bakryun0718@proton.me>
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-08-09 09:51:30 -03:00
committed by GitHub
parent fed05a3207
commit a2eab58dde
3 changed files with 18 additions and 0 deletions

View File

@@ -12,6 +12,10 @@ export function createBetterSqliteAdapter(db: import("better-sqlite3").Database)
return db.name;
},
get inTransaction() {
return db.inTransaction;
},
prepare(sql: string): PreparedStatement {
const stmt = db.prepare(sql);
return {

View File

@@ -13,6 +13,8 @@ export interface SqliteAdapter {
readonly driver: "better-sqlite3" | "node:sqlite" | "bun:sqlite" | "sql.js";
readonly open: boolean;
readonly name: string;
/** Driver transaction state when exposed by the underlying SQLite implementation. */
readonly inTransaction?: boolean;
prepare(sql: string): PreparedStatement;
exec(sql: string): void;

View File

@@ -78,4 +78,16 @@ describe("betterSqliteAdapter", () => {
assert.equal(count.cnt, 0, "Rollback deve ter desfeito o insert");
adapter.close();
});
test("expõe o estado da transação sem vazar o driver bruto", () => {
const adapter = tryOpenSync(":memory:");
if (!adapter || adapter.driver !== "better-sqlite3") return;
assert.equal(adapter.inTransaction, false);
const inspect = adapter.transaction(() => adapter.inTransaction);
assert.equal(inspect(), true);
assert.equal(adapter.inTransaction, false);
adapter.close();
});
});