(I am using node-oracledb thin client v6.2.0)
When I do a simple Select statement like this:
connection.execute( mySqlstring, {}, { outFormat: oracledb.OUT_FORMAT_OBJECT });
The result has metaData like this:
metaData: [
{
name: 'ID',
dbType: [DbType DB_TYPE_NUMBER],
nullable: false,
precision: 10,
scale: 0,
dbTypeName: 'NUMBER',
fetchType: [DbType DB_TYPE_NUMBER],
converter: [Function: converter]
},
But because Electron uses Proxy to send data to the renderer, only valid objects can be send. And dbType
, fetchType
and converter
make this not a valid object.
But I do need the metaData.
This works:
return JSON.parse(JSON.stringify(result,null,2));
But is of course not what I want.
Should I set other options? Or do I have to write code to exclude these fields?
Update
(answers to @christopher-jones)
This is the error I get:
Error sending from webFrameMain: Error: Failed to serialize arguments
at s.send (node:electron/js2c/browser_init:2:94175)
at _.sendToFrame (node:electron/js2c/browser_init:2:79803)
at e.reply (node:electron/js2c/browser_init:2:87292)
...
Also I now found out that, looking at it while debugging, that for instance dbType
is an object:
I guess I expect that node-oracledb would have an option to output something that could easily be turned into JSON.
This is the code I am executing:
export class ControllerDatabaseExecuteSql implements IIpcChannel {
readonly name: string = ipcChannels.DatabaseExecuteSql;
async handle(event: IpcMainEvent, id: string | null, args: any[]): Promise<void> {
event.reply(`${this.name}-#${id}#${ipcReply}`, await _DatabaseExecuteSql( args[0] ));
}
}
So it is the return value of _DatabaseExecuteSql()
that is sent back using event.reply()
.
So I did what Christopher Jones proposed: