SQL stream In the coding example, it behaves like CPYF, so let's code it in the same way. Create a physical file to copy to. I changed it a little because it was a big deal. (Change the attributes of LNAME and FNAME, change TOKUTEN to TENSU, change the record format)
MYLIB/MEMBER2.PF
*****************************************************************
*File ID: MEMBER2
*****************************************************************
A R MEMBER2R TEXT('member')
*
A ID 3S 0 COLHDG(' ID ')
A LNAME 6G COLHDG('Last name')
A FNAME 12J COLHDG('name')
A PROF 40O COLHDG('profile')
A TENSU 7P 3 COLHDG('Score')
SQLstream.js
var jt400 = require("node-jt400");
var JSONStream = require("JSONStream");
var express = require("express");
var app = express();
var pool = jt400.pool({ host: '192.168.X.XXX', user: 'MYUSER', password: 'MYPASS' });
var server = app.listen(8888, function () {
console.log("curl http://localhost:" + server.address().port + '/~');
});
app.get("/stream", function (req, res, next) {
pool.createReadStream("select * from member")
.pipe(JSONStream.parse([true]))
.pipe(pool.createWriteStream("insert into member2 (ID,FNAME,LNAME,PROF,TENSU) VALUES(?,?,?,?,?)"));
res.send('end');
});
Try to run it. Execution result
The surname and first name were correctly replaced and set.
Recommended Posts