How to Add NPM Module (Decimal) to ArangoDB for doing ACID Transactions then

arangodb, module, node.js, npm, package

Solution

Once you have the decimal module at the proper location and you can require it properly inside arangod, you should be able to use it inside a transaction like this:

db._executeTransaction({ 
  collections: { }, 
  action: function (params) { 
    var Decimal = require("decimal"); 
    return Decimal(params.foo).add(params.bar).toNumber(); 
  }, 
  params: { 
    foo: '1.1', 
    bar: '2.2' 
  } 
});

If your transactions need to access collection, you obviously need to specify their names in the "collections" attribute, e.g.

db._executeTransaction({ 
  collections: { 
    write: [ "test" ]
  }, 
  action: function (params) { 
    var Decimal = require("decimal");
    var collection = require("org/arangodb").db.test;
    var amount = Decimal(params.foo).add(params.bar).toNumber(); 

    return collection.save({ _key: params.key, amount: amount }); 
  }, 
  params: { 
    key: "mykey",
    foo: '1.1', 
    bar: '2.2' 
  } 
});

Problem

I would like to do ACID Transactions with ArangoDB. And I would like to send the transaction Code (nodejs-code) to the ArangoDB server where it will then be executed and hopefully commited or rolled back if it fails. But at the ArangoDB serverside I need the NPM Decimal module or called package installed. How do install it, and how do I access that particular module from the transaction code within? Greetings and thanks.

Original source

Related problems