From 18d954d3615a784ac05435b401ba41d708818dcf Mon Sep 17 00:00:00 2001 From: Mikhail Chechnev Date: Tue, 9 Oct 2018 21:45:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20Node=20Oracle=20=D0=B8=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=20?= =?UTF-8?q?=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.js | 5 ++++ index.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 13 ++++++++++ package.json | 23 ++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 config.js create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/config.js b/config.js new file mode 100644 index 0000000..5ab90c0 --- /dev/null +++ b/config.js @@ -0,0 +1,5 @@ +module.exports = { + user: "parus", + password: "parus", + connectString: "DEMOP_CITKSERV" +}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..2e333d8 --- /dev/null +++ b/index.js @@ -0,0 +1,62 @@ +var oracledb = require("oracledb"); +var dbConfig = require("./config.js"); + +// Get a non-pooled connection +oracledb.getConnection( + { + user: dbConfig.user, + password: dbConfig.password, + connectString: dbConfig.connectString + }, + function(err, connection) { + if (err) { + console.error(err.message); + return; + } + connection.execute( + // The statement to execute + "SELECT rn, agnabbr FROM agnlist WHERE rn = :id", + + // The "bind value" 180 for the bind variable ":id" + [1431890], + + // execute() options argument. Since the query only returns one + // row, we can optimize memory usage by reducing the default + // maxRows value. For the complete list of other options see + // the documentation. + { + maxRows: 1 + //, outFormat: oracledb.OBJECT // query result format + //, extendedMetaData: true // get extra metadata + //, fetchArraySize: 100 // internal buffer allocation size for tuning + }, + + // The callback function handles the SQL execution results + function(err, result) { + if (err) { + console.error(err.message); + setTimeout(() => { + doRelease(connection); + }, 2000); + return; + } + console.log(result.metaData); // [ { name: 'DEPARTMENT_ID' }, { name: 'DEPARTMENT_NAME' } ] + console.log(result.rows); // [ [ 180, 'Construction' ] ] + setTimeout(() => { + doRelease(connection); + }, 2000); + } + ); + } +); + +// Note: connections should always be released when not needed +function doRelease(connection) { + connection.close(function(err) { + if (err) { + console.log("Connection closed with erros: " + err.message); + } else { + console.log("Connection closed - no erros"); + } + }); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b6139cd --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "parus_exchange_service", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "oracledb": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/oracledb/-/oracledb-2.3.0.tgz", + "integrity": "sha512-zTG1elqQ3kdGiu93OcWYje3YCFO2kfLBTC1KjEyxIck8gnH9H2vAqrE5AgPdPmColIf961g3KwwxcwlEnX0CpA==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..39e6556 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "parus_exchange_service", + "version": "1.0.0", + "description": "Parus 8 and WEB API integration platform", + "main": "index.js", + "scripts": { + "start": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/CITKParus/ExchangeService.git" + }, + "author": "CITK Parus", + "license": "ISC", + "bugs": { + "url": "https://github.com/CITKParus/ExchangeService/issues" + }, + "homepage": "https://github.com/CITKParus/ExchangeService#readme", + "dependencies": { + "oracledb": "^2.3.0" + } +}