-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Ability to pass in odbc connection to transport #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Ability to pass in odbc connection to transport #320
Conversation
As written now closing of the odbc connection is based on if the |
Examples Using Existing ODBC ConnectionCallbacksconst { Connection, CommandCall } = require('itoolkit');
const { parseString } = require('xml2js');
const odbc = require('odbc');
odbc.connect('DSN=*LOCAL', (connectError, connection) => {
if (connectError) { throw connectError; }
const toolkit = new Connection({
transport: 'odbc',
transportOptions: {
odbcConnection: connection,
},
});
const command = new CommandCall({ type: 'cl', command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)' });
toolkit.add(command);
toolkit.run((error, xmlOutput) => {
if (error) { throw error; }
parseString(xmlOutput, (parseError, result) => {
if (parseError) { throw parseError; }
console.log(result);
// close odbc connection
connection.close((closeError) => {
if (closeError) { throw closeError; }
});
});
});
}); Promisesconst { Connection, CommandCall } = require('itoolkit');
const { parseString } = require('xml2js');
const odbc = require('odbc');
async function main() {
const connection = await odbc.connect('DSN=*LOCAL');
const toolkit = new Connection({
transport: 'odbc',
transportOptions: {
odbcConnection: connection,
},
});
const command = new CommandCall({ type: 'cl', command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)' });
toolkit.add(command);
// toolkit.run is asynchronous and invokes callback on completion
// therefore need to wrap this is call with a new promise when working with async/await
const p = new Promise((resolve, reject) => {
toolkit.run((error, xmlOutput) => {
if (error) { reject(error); }
parseString(xmlOutput, (parseError, result) => {
if (parseError) { reject(parseError); }
resolve(result);
});
});
});
const result = await p;
await connection.close(); // close odbc connection
return result;
}
main().then((result) => {
console.log(result);
}).catch((error) => {
console.error(error);
}); |
👋 Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed. |
Is this PR still being worked on? It would help us encourage use of the odbc transport if the open/close performance penalty were no longer a concern. |
Its been a minute since we worked on this. I still would like to get this merged as it would enhance performance. |
Hi @abmusse, did you ever discuss this with the team? The concept of this change seems like a no-brainer to me but I haven't tested it yet. |
Hi @brandonp42 , Thanks for the ping Its been a year and his change has been left on the shelf unattended. IIRC, some the points I wanted to discuss with the team was:
Could you help test things out and give feedback if you encounter "dead" connections or other issues? This would help move forward to getting this change merged in. mkdir ~/test-itoolkit-keep-odbc-open
cd ~/test-itoolkit-keep-odbc-open
npm init -y
npm install "https://github.com/abmusse/nodejs-itoolkit#odbc-transport-use-existing-connection" --save Here is an example passing in the odbc connection: #320 (comment) |
Sure, I will try to do some testing with this. My use case is for incoming API connections via Express where we call our internal service programs to do things and then return data back to the caller. So for that we generally want to use connection pools that stay alive for performance. As part of that we're also running a custom version of XMLSERVICE that I've fixed some bugs in. |
FYI I've re-based this PR with the latest changes on the main branch. |
Resolves #279
Resolves #282