Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
I have created something, out of necessity as all good things, that lets me use something more clever then csv to import/export data to/from Node.js. It could perhaps be something that would be useful for more than me
It's a node module call qvx that can be found at kmpm/node-qvx · GitHub or installed by running npm install.
It's a couple of stream tranform implementations that reads (qvx.Inbound) and writes (qvx.Outbound) qvx data.
It's currently in a Alpha stage and it doesn't implement everything in the Qvx file format yet but it "works for me" tm.
I also made a demo http server using Hapi and the qvx module that you can find here kmpm/node-qvxserver · GitHub.
Example javascript for serving qvx from a json file using Hapi and streams.
function (request, reply) {
var fields = {
'AddressNumber': {type: DataTypes.FLOAT(8)},
'ItemNumber': {type: DataTypes.BIGINT().DECIMALS(0)},
'InvoiceDate': {type: DataTypes.TIMESTAMP('utf-8', 1)},
'PromisedDeliveryDate': {type: DataTypes.TIMESTAMP}, //'2010-11-19T23:00:00.000Z',
'Date': {type: DataTypes.TIMESTAMP}, //'2010-11-19T23:00:00.000Z',
'InvoiceNumber': {type: DataTypes.FLOAT(8)},
'OrderNumber': {type: DataTypes.FLOAT(8)},
'ItemDesc': {type: DataTypes.STRING('utf-8', 4)},
'SalesQty': {type: DataTypes.BIGINT().DECIMALS(0)},
'OpenQty': {type: DataTypes.BIGINT().DECIMALS(0)},
'OpenOrder': {type: DataTypes.BIGINT().DECIMALS(0)},
'GrossSales': {type: DataTypes.BIGINT().DECIMALS(0)},
'Sales': {type: DataTypes.BIGINT().DECIMALS(0)},
'BackOrder': {type: DataTypes.BIGINT().DECIMALS(0)},
'Cost': {type: DataTypes.BCD(18).DECIMALS(4)},
'Margin': {type: DataTypes.BCD(18).DECIMALS(4)},
'SalesKey': {type: DataTypes.STRING('utf-8', 4)},
'ofDaysLate': {type: DataTypes.BIGINT().DECIMALS(0)},
'ofDaystoShip': {type: DataTypes.BIGINT().DECIMALS(0)}
};
var schema = new qvx.Schema({
tableName: 'test',
recordFormat: 'object',
fields: fields
});
var outbound = new qvx.Outbound(schema);
var dataStream = fs.createReadStream(path.join(__dirname, 'test_data.json'))
.pipe(es.split())
.pipe(es.parse())
.pipe(outbound);
reply(dataStream)
.type('application/octet-stream')
.header('content-disposition', 'attachment; filename=test.qvx;');
}