Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const oracledb = require('oracledb');
- const dbConfig = require('../config/database.js');
- async function initialize() {
- await oracledb.createPool(dbConfig.SinhVien);
- }
- module.exports.initialize = initialize;
- async function close() {
- await oracledb.getPool().close();
- }
- module.exports.close = close;
- function simpleExecute(statement, binds = [], opts = {}) {
- return new Promise(async (resolve, reject) => {
- let conn;
- opts.outFormat = oracledb.OBJECT;
- opts.autoCommit = true;
- try {
- conn = await oracledb.getConnection();
- const result = await conn.execute(statement, binds, opts);
- resolve(result);
- } catch (err) {
- reject(err);
- } finally {
- if (conn) { // conn assignment worked, need to close
- try {
- await conn.close();
- } catch (err) {
- console.log(err);
- }
- }
- }
- });
- }
- module.exports.simpleExecute = simpleExecute;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement