Skip to content
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

Add Explicit Resource Management to oracledb objects #1631

Open
sosoba opened this issue Dec 5, 2023 · 1 comment
Open

Add Explicit Resource Management to oracledb objects #1631

sosoba opened this issue Dec 5, 2023 · 1 comment

Comments

@sosoba
Copy link

sosoba commented Dec 5, 2023

  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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants