Closed VegarRingdalAibel closed 1 year ago
There might not be a saving, since a JS call to stringify would likely still occur - but just in the driver layer not the app layer.
Have you looked at using Oracle DB JSON functionality in the query itself?
For completeness to make sure we're talking about the same things, it would be helpful if you could share exact snippets of the data structures you want.
Hi
Oracle DB JSON is not an option at the moment.
Added a small same under. But if you need to use stringify in the driver layer then there is nothing to save really. I though you built the string in the driver c code and used v8/nodejs parse it, to give us the objects/array, if so it would be a lot to save.
let buffer: any[] = [];
const maxSize = 50;
const stream = connection.queryStream(sqlString, sqlBindings, {
outFormat: OracleDB.OUT_FORMAT_ARRAY
});
stream?.on("data", function (data: any) {
buffer.push(data);
// now I get array : ['somedata1', 'somedata1', 'somedata1', 'somedata1', 1,false, null]
// but if I got stringfied array '["somedata1","somedata1","somedata1","somedata1",1,false,null]'
// It would save my from using JSON stringify, I would just build up a string and send it.
if (buffer.length > maxSize) {
sendData(JSON.stringify(buffer));
buffer = [];
}
});
With the general direction heading to a pure JS driver implementation, there are no plans to use Node-API C code functionality for JSON. The solutions for getting JSON in apps are to use the Oracle DB JSON type or to stringify in the application, possibly with a node-oracledb 6.0 fetch type handler converted if that makes calling JSON.stringify()
more convenient for the architecture.
Atm I use queryStream and stream my result in batches of 50 records to client on lage datasets. To do this I have a "buffer" array I put data from
stream?.on("data",..
When it have 50 records I use JSON.stringify and send it with send method expressjs have.Normally use
OracleDB.OUT_FORMAT_ARRAY
for applications, but also supportOracleDB.OUT_FORMAT_OBJECT
when user expects normal json format.If it was possible to get array or object as string right away I would probably save my nodejs instnace from doing a lot of work. Probably save memory and CPU.
So would have been very useful if we maybe get 2 more options in the outformat
OracleDB.OUT_FORMAT_OBJECT_STRING
OracleDB.OUT_FORMAT_ARRAY_STRING
Would this be possible? I assume the c code might need to work less to do this ?