JSPM

  • Created
  • Published
  • Downloads 796
  • Score
    100M100P100Q100828F
  • 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.
});

IFS read

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