node-trans
v0.2.1
Published
execute trans commands and parse returned value in to json
Downloads
23
Readme
Node-Trans
Provide a simple interface to work with trans from nodejs
Install
npm install --save node-trans
Limitations
Currently not support transinfo because of its returned format is different from sql trans.
API
There are 3 classes exported by this lib:
Client
: handle connections to the actual trans server and executecommand
Command
: create trans commandsParser
: handle outputs from trans server and parse them to JS Objects
Example:
var trans = require('node-trans');
var client = new trans.Client('phoenix', 31005);
var command = new trans.Command('load_ad_info');
var params = trans.Command.Param({
ad_id: 12
// sample: trans.Command.MultiParam([1,'hai', 3])
});
// execute it!
client.execute(command, params)
.then(function (output) {
console.log(output);
/*
{
status: 'TRANS_OK',
data: {
load_ad_info: [
account_id: '1',
action_id: '1'
ad_id: '12'
//...
]
},
// if there's some trans error occurs
error: {
type: 'TRANS_DATABASE_ERROR',
message: 'ERROR: ....'
}
}
*/
})
.catch(function (ex) {
// handle connection errors, parse errors
})