oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.24k stars 1.07k forks source link

using connection pool in nextjs #1638

Closed babpulss closed 3 months ago

babpulss commented 5 months ago

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 commented 5 months ago

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);

}

sharadraju commented 5 months ago

@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?

sudarshan12s commented 4 months ago

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.

sharadraju commented 3 months ago

Closing this as not an issue with node-oracledb