JSPM

  • Created
  • Published
  • Downloads 873
  • Score
    100M100P100Q99243F
  • License mit

jt400 wrapper for nodejs

Package Exports

  • node-jt400

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-jt400) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-jt400

nodejs jt400 wrapper

Configure

var pool = require('node-jt400').pool({host: 'myhost', user: 'myuser', password: 'xxx'});

SQL query

pool.query('SELECT FIELD1, FIELD2 FROM FOO WHERE BAR=? AND BAZ=?', [1, 'a'])
.then(function (result) {
    var field1 = result[0].FIELD1;
    ...
});

SQL stream

pool.createReadStream('SELECT FIELD1, FIELD2 FROM FOO WHERE BAR=? AND BAZ=?', [1, 'a'])
.pipe(JSONStream.parse([true]))
.pipe(pool.createWriteStream('INSERT INTO FOO2 (F1, F2) VALUES(?, ?)'));

SQL update

pool.update('update FOO set BAR=? WHERE BAZ=?', [1, 'a'])
.then(function (nUpdated) {
    ...
});

SQL insert

//insert list in one statement
var tableName = 'foo',
    idColumn  = 'fooid',
    rows = [
        {FIELD1: 1, FIELD2: 'a'},
        {FIELD1: 1, FIELD2: 'a'}
    ];
pool.insertList(tableName, idColumn, rows)
.then(function (listOfGeneratedIds) {
    ...
});

SQL batch update

//insert list in one statement
var data = [
        [1, 'a'],
        [2, 'b']
    ];
pool.batchUpdate('INSERT INTO FOO (FIELD1, FIELD2) VALUES(?,?)', data)
.then(function (result) {
    //result is number of updated rows for each row. [1, 1] in this case.
});

Transactions

pool.transaction(function(transaction) {
    var fooId = 1;

    //transaction object has the same api as the pool object.
    //The transaction is commited on success and rolled back on failure.
    return transaction.update('INSERT INTO FOO (FOOID, FIELD2) VALUES(?,?)', [fooId, 'a']).then(function() {
        return transaction.update('update BAR set FOOID=? where BARID=?', [fooId , 2])
    });
});

IFS read

var ifs = pool.ifs();
ifs.createReadStream('/foo/bar.txt');