Neglected Puppy Market

    node-trans

    0.2.1 • Public • Published

    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:

    1. Client: handle connections to the actual trans server and execute command
    2. Command: create trans commands
    3. Parser: 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
      })

    Install

    npm i node-trans

    DownloadsWeekly Downloads

    0

    Version

    0.2.1

    License

    ISC

    Last publish

    Collaborators

    • tungv