mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-12 02:02:13 +03:00
fix(types): expose SQLite transaction state (#9848)
Co-authored-by: backryun <bakryun0718@proton.me>
This commit is contained in:
committed by
GitHub
parent
fed05a3207
commit
a2eab58dde
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user