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

Add Explicit Resource Management to oracledb objects #1631

Open sosoba opened 7 months ago

sosoba commented 7 months ago
  1. Describe your new request in detail

TS/JS, like other programming languages, introduces a syntax for guaranteed resource release (using). Ex.:

using pool = await oracledb.createPool({...});
using connection = await pool.getConnection();
using result = await connection.execute( 'SELECT b FROM no_lobs WHERE id = :id', { id: 2 });
using lob = result.rows[0][0];
lob.pipe(response);

which is equivalent to:

const pool = await oracledb.createPool({...});
try {
  const connection = await pool.getConnection();
  try {
    const result = await connection.execute( 'SELECT b FROM no_lobs WHERE id = :id', { id: 2 });
    try {
      const lob = result.rows[0][0];
      try {
        lob.pipe(response);
      } finally {
        lob.destroy();
      }
    } finally {
      await result.close();
    }
  } finally {
    await connection.close();
  }
} finally {
  await pool.close();
}

I think it is worth expanding the library to support this solution.

  1. Give supporting information about tools.

The implementation involves adding aliased symbolic methods to close / destroy. See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management https://tc39.es/proposal-explicit-resource-management/

sharadraju commented 7 months ago

Thanks @sosoba for the suggestion. We will be looking into this.