Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. const oracledb = require('oracledb');
  2. const dbConfig = require('../config/database.js');
  3.  
  4. async function initialize() {
  5. await oracledb.createPool(dbConfig.SinhVien);
  6. }
  7.  
  8. module.exports.initialize = initialize;
  9.  
  10. async function close() {
  11. await oracledb.getPool().close();
  12. }
  13.  
  14. module.exports.close = close;
  15.  
  16. function simpleExecute(statement, binds = [], opts = {}) {
  17. return new Promise(async (resolve, reject) => {
  18. let conn;
  19. opts.outFormat = oracledb.OBJECT;
  20. opts.autoCommit = true;
  21. try {
  22. conn = await oracledb.getConnection();
  23. const result = await conn.execute(statement, binds, opts);
  24. resolve(result);
  25. } catch (err) {
  26. reject(err);
  27. } finally {
  28. if (conn) { // conn assignment worked, need to close
  29. try {
  30. await conn.close();
  31. } catch (err) {
  32. console.log(err);
  33. }
  34. }
  35. }
  36. });
  37. }
  38. module.exports.simpleExecute = simpleExecute;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement