简体   繁体   English

如何将NPM模块(十进制)添加到ArangoDB以进行ACID事务

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

I would like to do ACID Transactions with ArangoDB. 我想用ArangoDB进行ACID交易。 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. 我想将事务代码(nodejs-code)发送到ArangoDB服务器,然后在那里执行它,如果失败则希望提交或回滚。 But at the ArangoDB serverside I need the NPM Decimal module or called package installed. 但是在ArangoDB服务器端,我需要安装NPM Decimal模块或称为软件包。

How do install it, and how do I access that particular module from the transaction code within? 如何安装它,以及如何从事务代码中访问该特定模块?

Greetings and thanks. 问候和感谢。

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: 一旦你在适当的位置有十进制模块,你可以在arangod内正确地要求它,你应该能够在这样的事务中使用它:

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, eg 如果您的交易需要访问集合,您显然需要在“集合”属性中指定其名称,例如

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' 
  } 
});

stj has already answered the transaction part of the question. stj已经回答了问题的交易部分。 Regarding installing NPM modules. 关于安装NPM模块。

Switch into the folder 切换到文件夹

/usr/share/arangodb/js/common/node

and execute 并执行

npm install decimal

This should install the NODE module for both the server (arangod) and the shell (arangosh). 这应该为服务器(arangod)和shell(arangosh)安装NODE模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM