node-oracledb icon indicating copy to clipboard operation
node-oracledb copied to clipboard

using connection pool in nextjs

Open babpulss opened this issue 1 year ago • 3 comments

I'm going to talk about the solution to the problem of creating a connection pool when using nextjs. The page that creates the connection pool was imported from each page, but due to the independent execution environment, the connection pool was created for each page, and this was not done with a consistent singleton, which led to unsatisfactory results. As a solution, I came up with a way to hold the created pool in a globalThis. ` declare global { var pool: Pool }

globalThis.pool = await createPool({ user: process.env.ORACLE_USER, password: process.env.ORACLE_PASSWORD, connectString: process.env.ORACLE_CONNECTSTRING, configDir: process.env.ORACLE_CONFIG_DIR, }); ` It turns out that this is a common pattern used by other nodejs libraries like prisma etc..

  1. What is the link to the documentation section that needs improving?

  2. Describe the confusion

  3. Suggest changes that would help

babpulss avatar Jan 17 '24 00:01 babpulss

and close pool in next.config.js process .once('SIGTERM', closePool) .once('SIGINT', closePool);

async function closePool() { try { await globalThis?.pool?.close() process.exit(0);

}

babpulss avatar Jan 17 '24 00:01 babpulss

@babpulss Thank you for trying node-oracledb with Next.js. However, it is not clear on the exact requirement from node-oracledb with the connection pool as you have provided a solution.

What is the change that you require on the node-oracledb side?

sharadraju avatar Jan 29 '24 10:01 sharadraju

Hi @babpulss , The management of pool ( or multiple pools) is done at the application layer and varies based on use-cases . Here is an example included for a typical web application.

From the node-oracledb driver , it provides various timeout parameters which can be used to control the connections/resources for a web application.

sudarshan12s avatar Feb 07 '24 16:02 sudarshan12s

Closing this as not an issue with node-oracledb

sharadraju avatar Mar 11 '24 17:03 sharadraju