From 6e34f4d3c29a457f0e37d9cf1d144a23ed0f40e0 Mon Sep 17 00:00:00 2001 From: Mikhail Chechnev Date: Thu, 1 Nov 2018 20:30:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=D1=8B=D0=B9=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=8B=20=D1=81=20=D0=91=D0=94=20=D0=9F=D0=9F=20=D0=9F=D0=B0?= =?UTF-8?q?=D1=80=D1=83=D1=81=208=20(=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/parus_db.js | 125 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 modules/parus_db.js diff --git a/modules/parus_db.js b/modules/parus_db.js new file mode 100644 index 0000000..e2449a2 --- /dev/null +++ b/modules/parus_db.js @@ -0,0 +1,125 @@ +/* + Сервис интеграции ПП Парус 8 с WEB API + Дополнительный модуль: работа с БД ПП Парус 8 (Oracle) +*/ + +//---------------------- +// Подключение библиотек +//---------------------- + +const oracledb = require("oracledb"); //Работа с СУБД Oracle + +//------------ +// Тело модуля +//------------ + +//Подключение к БД +const connect = prms => { + return new Promise((resolve, reject) => { + oracledb.getConnection( + { + user: prms.user, + password: prms.password, + connectString: prms.connectString + }, + function(err, connection) { + if (err) { + reject(err); + } else { + resolve(connection); + } + } + ); + }); +}; + +//Отключение от БД +const disconnect = connection => { + return new Promise((resolve, reject) => { + if (connection) { + connection.close(function(err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("No connection specified")); + } + }); +}; + +//Исполнение запроса +const execute = prms => { + console.log("EXECUTE"); +}; + +//----------------- +// Интерфейс модуля +//----------------- + +exports.connect = connect; +exports.disconnect = disconnect; +exports.execute = execute; + +/* +oracledb.getConnection( + { + user: cfg.dbConnect.user, + password: cfg.dbConnect.password, + connectString: cfg.dbConnect.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"); + } + }); +} +*/