Skip to content

feat: Ability to pass in odbc connection to transport - #320

Closed
abmusse wants to merge 2 commits into
IBM:masterfrom
abmusse:odbc-transport-use-existing-connection
Closed

feat: Ability to pass in odbc connection to transport#320
abmusse wants to merge 2 commits into
IBM:masterfrom
abmusse:odbc-transport-use-existing-connection

Conversation

@abmusse

Copy link
Copy Markdown
Member

Resolves#279
Resolves#282

@abmusse

Copy link
Copy Markdown
MemberAuthor

As written now closing of the odbc connection is based on if the odbcConnection transport object was set. When a connection is passed in we do not close it. Otherwise we create the connection, run the query, and close it. #282 (comment) posses a good question if we should allow closing of the connection to be configurable.

@abmusseabmusse added this to the Version 1.1 milestone Jan 19, 2021
@abmusse

abmusse commented Jan 20, 2021

Copy link
Copy Markdown
MemberAuthor

Examples Using Existing ODBC Connection

Callbacks

const{ Connection, CommandCall }=require('itoolkit');const{ parseString }=require('xml2js');constodbc=require('odbc');odbc.connect('DSN=*LOCAL',(connectError,connection)=>{if(connectError){throwconnectError;}consttoolkit=newConnection({transport: 'odbc',transportOptions: {odbcConnection: connection,},});constcommand=newCommandCall({type: 'cl',command: 'RTVJOBA USRLIBL(?) SYSLIBL(?)'});toolkit.add(command);toolkit.run((error,xmlOutput)=>{if(error){throwerror;}parseString(xmlOutput,(parseError,result)=>{if(parseError){throwparseError;}console.log(result);// close odbc connectionconnection.close((closeError)=>{if(closeError){throwcloseError;}});});});});

Promises

const{ Connection, CommandCall }=require('itoolkit');const{ parseString }=require('xml2js');constodbc=require('odbc');asyncfunctionmain(){constconnection=awaitodbc.connect('DSN=*LOCAL');consttoolkit=newConnection({transport: 'odbc',transportOptions: {odbcConnection: connection,},});constcommand=newCommandCall({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 constp=newPromise((resolve,reject)=>{toolkit.run((error,xmlOutput)=>{if(error){reject(error);}parseString(xmlOutput,(parseError,result)=>{if(parseError){reject(parseError);}resolve(result);});});});constresult=awaitp;awaitconnection.close();// close odbc connectionreturnresult;}main().then((result)=>{console.log(result);}).catch((error)=>{console.error(error);});

@abmusse
abmusse marked this pull request as ready for review January 20, 2021 20:04
@abmusse
abmusse requested a review from kadlerJanuary 20, 2021 20:05
@github-actions

Copy link
Copy Markdown

👋 Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

@abmusseabmusse added keep-open Exempts stale action from auto closing the issue/pr. and removed stale labels Feb 20, 2021
@alanseiden

Copy link
Copy Markdown
Contributor

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.

@abmusse

Copy link
Copy Markdown
MemberAuthor

Its been a minute since we worked on this. I still would like to get this merged as it would enhance performance.
Need to have a discussion with the team on the strategy for this change going forward.

@brandonp42

Copy link
Copy Markdown

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.

@abmusse

Copy link
Copy Markdown
MemberAuthor

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.
We haven't discussed the points of concern due to other priorities.

IIRC, some the points I wanted to discuss with the team was:

  • Is there a default timeout for odbc connection? If so is the time out configurable to keep the connection alive indefientely?

  • How to handling "dead" connections? Should we just reconnect if the expected connection is "dead" Currently this PR does not make reconnect attempts. Maybe this could be handled by passing DSN / connection details in. Each call check if the passed in connection is connected. if not use the DSN / connection details to create the connection and continue.

  • Also was considering adding promise support as mentioned here Investigate supporting Promises and Callbacks #322 (comment) (For now though I think having the performance boost keep a connection open is higher priority) This would be more involved as some of transports don't support promises (ssh2 library)

Could you help test things out and give feedback if you encounter "dead" connections or other issues?
Also, Does your use case keep the connection open for long time?

This would help move forward to getting this change merged in.
If you agree I would re-base this PR with latest main branch.
Then you can install this version of itoolkit with odbc changes with:

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)

@brandonp42

Copy link
Copy Markdown

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.

@abmusse

abmusse commented Oct 19, 2023

Copy link
Copy Markdown
MemberAuthor

FYI I've re-based this PR with the latest changes on the main branch.

@abmusseabmusse closed this by deleting the head repository Nov 21, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep-openExempts stale action from auto closing the issue/pr.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is the SQL feature going to be removed from the toolkit?

3 participants

@abmusse@alanseiden@brandonp42