[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: wallet-core: primitive DB tri
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: wallet-core: primitive DB trigger support |
Date: |
Wed, 10 Apr 2024 14:50:55 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new 4725d98ed wallet-core: primitive DB trigger support
4725d98ed is described below
commit 4725d98ed550b8d38420438d307ce5dbf97e147d
Author: Florian Dold <florian@dold.me>
AuthorDate: Wed Apr 10 14:50:53 2024 +0200
wallet-core: primitive DB trigger support
---
packages/taler-wallet-core/src/query.ts | 35 +++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/packages/taler-wallet-core/src/query.ts
b/packages/taler-wallet-core/src/query.ts
index cffad84df..d78e9bc6e 100644
--- a/packages/taler-wallet-core/src/query.ts
+++ b/packages/taler-wallet-core/src/query.ts
@@ -31,6 +31,7 @@ import {
IDBKeyRange,
IDBRequest,
IDBTransaction,
+ IDBTransactionMode,
IDBValidKey,
IDBVersionChangeEvent,
} from "@gnu-taler/idb-bridge";
@@ -766,6 +767,7 @@ function makeWriteContext(
export interface DbAccess<StoreMap> {
idbHandle(): IDBDatabase;
+
runAllStoresReadWriteTx<T>(
options: {
label?: string;
@@ -774,6 +776,7 @@ export interface DbAccess<StoreMap> {
tx: DbReadWriteTransaction<StoreMap, Array<StoreNames<StoreMap>>>,
) => Promise<T>,
): Promise<T>;
+
runAllStoresReadOnlyTx<T>(
options: {
label?: string;
@@ -782,16 +785,25 @@ export interface DbAccess<StoreMap> {
tx: DbReadOnlyTransaction<StoreMap, Array<StoreNames<StoreMap>>>,
) => Promise<T>,
): Promise<T>;
+
runReadWriteTx<T, StoreNameArray extends Array<StoreNames<StoreMap>>>(
storeNames: StoreNameArray,
txf: (tx: DbReadWriteTransaction<StoreMap, StoreNameArray>) => Promise<T>,
): Promise<T>;
+
runReadOnlyTx<T, StoreNameArray extends Array<StoreNames<StoreMap>>>(
storeNames: StoreNameArray,
txf: (tx: DbReadOnlyTransaction<StoreMap, StoreNameArray>) => Promise<T>,
): Promise<T>;
}
+export interface TriggerSpec {
+ /**
+ * Trigger run after every successful commit, run outside of the transaction.
+ */
+ afterCommit?: (mode: IDBTransactionMode, stores: string[]) => void;
+}
+
/**
* Type-safe access to a database with a particular store map.
*
@@ -801,6 +813,7 @@ export class DbAccessImpl<StoreMap> implements
DbAccess<StoreMap> {
constructor(
private db: IDBDatabase,
private stores: StoreMap,
+ private triggers: TriggerSpec = {},
) {}
idbHandle(): IDBDatabase {
@@ -861,9 +874,14 @@ export class DbAccessImpl<StoreMap> implements
DbAccess<StoreMap> {
strStoreNames.push(swi.storeName);
accessibleStores[swi.storeName] = swi;
}
- const tx = this.db.transaction(strStoreNames, "readwrite");
+ const mode = "readwrite";
+ const tx = this.db.transaction(strStoreNames, mode);
const writeContext = makeWriteContext(tx, accessibleStores);
- return runTx(tx, writeContext, txf);
+ const res = runTx(tx, writeContext, txf);
+ if (this.triggers.afterCommit) {
+ this.triggers.afterCommit(mode, strStoreNames);
+ }
+ return res;
}
runReadOnlyTx<T, StoreNameArray extends Array<StoreNames<StoreMap>>>(
@@ -878,8 +896,17 @@ export class DbAccessImpl<StoreMap> implements
DbAccess<StoreMap> {
strStoreNames.push(swi.storeName);
accessibleStores[swi.storeName] = swi;
}
- const tx = this.db.transaction(strStoreNames, "readonly");
+ const mode = "readonly";
+ const tx = this.db.transaction(strStoreNames, mode);
const readContext = makeReadContext(tx, accessibleStores);
- return runTx(tx, readContext, txf);
+ const res = runTx(tx, readContext, txf);
+ if (this.triggers.afterCommit) {
+ this.triggers.afterCommit(mode, strStoreNames);
+ }
+ return res;
}
+
+ registerPostCommitTrigger(args: {
+ handler: (storeNames: string[]) => void;
+ }): void {}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: wallet-core: primitive DB trigger support,
gnunet <=