Dpack get data Node : V10
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

132 行
2.9 KiB

  1. var oracledb = require("oracledb");
  2. var log = require("./log.js");
  3. var util = require("./util.js");
  4. var getPoolConnection = async function (config) {
  5. let pool;
  6. try {
  7. pool = await oracledb.createPool({
  8. user: config.user,
  9. password: config.password, // mypw contains the hr schema password
  10. connectString: `${config.ip_address}:${config.port}/${config.dbname}`,
  11. queueTimeout: 600000,
  12. });
  13. } catch (e) {
  14. pool.close();
  15. return e.message;
  16. } finally {
  17. if (pool) {
  18. return pool;
  19. }
  20. }
  21. };
  22. var getConnected = async function (config, sql, params) {
  23. let pool;
  24. let conn;
  25. var result;
  26. try {
  27. pool = await getPoolConnection(config);
  28. conn = await pool.getConnection();
  29. var changeTz = await conn.execute(
  30. `
  31. begin
  32. execute immediate 'alter session set time_zone=''UTC''';
  33. end;
  34. `,
  35. {}
  36. );
  37. data = await conn.execute(sql, params, { outFormat: oracledb.OBJECT });
  38. result = { STATUS: 1, DATA: data.rows };
  39. } catch (e) {
  40. result = { STATUS: 0, DATA: e.message };
  41. util.throwNotif(e.message);
  42. log.createLog(0, e.message);
  43. } finally {
  44. if (conn) {
  45. await conn.close();
  46. }
  47. if (pool) {
  48. await pool.close();
  49. }
  50. return result;
  51. }
  52. };
  53. var getConnectedInsert = async function (config, sql, params) {
  54. let pool;
  55. let conn;
  56. var result;
  57. try {
  58. pool = await getPoolConnection(config);
  59. conn = await pool.getConnection();
  60. var changeTz = await conn.execute(
  61. `
  62. begin
  63. execute immediate 'alter session set time_zone=''UTC''';
  64. end;
  65. `,
  66. {}
  67. );
  68. data = await conn.execute(sql, params, { outFormat: oracledb.OBJECT });
  69. await conn.commit();
  70. result = { STATUS: 1, DATA: data };
  71. } catch (e) {
  72. await conn.rollback();
  73. result = { STATUS: 0, DATA: e.message };
  74. log.createLog(0, e.message);
  75. util.throwNotif(e.message);
  76. } finally {
  77. if (conn) {
  78. await conn.close();
  79. }
  80. if (pool) {
  81. await pool.close();
  82. }
  83. return result;
  84. }
  85. };
  86. var getConnectedInsertMany = async function (config, sql, params) {
  87. let pool;
  88. let conn;
  89. var result;
  90. try {
  91. pool = await getPoolConnection(config);
  92. conn = await pool.getConnection();
  93. var changeTz = await conn.execute(
  94. `
  95. begin
  96. execute immediate 'alter session set time_zone=''UTC''';
  97. end;
  98. `,
  99. {}
  100. );
  101. data = await conn.executeMany(sql, params, { outFormat: oracledb.OBJECT });
  102. await conn.commit();
  103. result = { STATUS: 1, DATA: data };
  104. } catch (e) {
  105. await conn.rollback();
  106. result = { STATUS: 0, DATA: e };
  107. } finally {
  108. if (conn) {
  109. await conn.close();
  110. }
  111. if (pool) {
  112. await pool.close();
  113. }
  114. return result;
  115. }
  116. };
  117. module.exports.getConnected = getConnected;
  118. module.exports.getConnectedInsert = getConnectedInsert;
  119. module.exports.getConnectedInsertMany = getConnectedInsertMany;