dlwicksell/nodem

Are lock and unlock needed for transaction commit?

wpoosanguansit opened this issue · 2 comments

I am not sure how do we guarantee transaction for set. I am using nodem with globals and I tried to do

var globals = new globals.GlobalNode("root", ["1"]);
db.lock(globals);
set to save data
db.unlock(globals);

And I do get SyntaxError: Need to supply a global property exception.

It would be great if there is an example for doing things transactionally like multiple sets in a row. Thanks for your help.

Lock and unlock are different from a transaction. Transactions are not supported by NodeM, for technical reasons. Though you can use NodeM, with the function API, to call MUMPS code that uses fully ACID transactions.

Your error is because the lock and unlock APIs require an argument which is a JavaScript object, containing the name of the global, and optionally, the global subscripts, that you wish to lock or unlock. E.g.

db.lock({global: 'dlw'});
db.unlock({global: 'dlw', subscripts: [1, 2, 3]});

Or you can call unlock with no arguments, and it will release all of the locks in the current process. The documentation for this is the same as the Caché documentation, which is linked in the README.md file at the root of NodeM.

Thank you for your help. I definitely have got a lot to unlearn and learn. It would be great if there would be a place where newbies like me can pick up on what is a recommended way to work with the library.