Closed mikeTWC1984 closed 8 months ago
If you are simply wanting to avoid asynchronicity in the callback, you can do:
db.transactionSync(() => {
var value = db.get(1);
db.put(2, "Yes, it's this simple!");
});
If you are wanting to ensure the transaction can span call scopes, you could do:
let commit;
db.transactionSync(() => new Promise(resolve => commit = resolve));
var value = db.get(1);
db.put(2, "Yes, it's this simple!");
commit();
OK, thanks. What I needed is second option. I work with a storage engine that uses lmdb as backend, so I cannot define that callback to perform multiple operation, needed a way to open transaction "globally". The option you provided worked for me.
Is there a way to use transaction without callback. E.g. just begin transaction, put values as needed and commit. Same way as node-lmdb: