-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
For my particular set-up, I need to access some of the properties of the driver without having the Oracle Client available. For instance, I need to access the BINDIN and BINDOUT properties.
At the point of import, everything is loaded and if the Oracle Client is not available, then an error is generated. It would be useful to be able to access the static properties of the instance without this dependency.
Let me drill more into the specifics. I am using the Cypress automation test framework, which executes tests in an isolated environment. This framework works excellently with the Oracle driver in general, allowing SQL queries to be wrapped in Cypress/Mocha style assertions like so...
cy.db(`SELECT 'something'
FROM dual`).should('eq', 'something');
As I have mentioned, tests run in an isolated environment, so when the above code is executed, Cypress farms off the DML to a separate Node.js process that instantiates the node-oracledb driver and then returns the serialised result. The SQL is not executed as part of the main process.
The above works absolutely fine.
Where things fall down is when I need to reference properties from the node-oracledb instance within a test.
Here is a actual test sample. The test verifies basic function calling with binds.
const oracledb = require('oracledb');
it('Can call a PL/SQL function with bind variables', function() {
let sql;
let binds;
sql = `BEGIN
:ret := test_data_management_pkg.func_test(:p1);
END;`;
binds = {
p1: 'Something',
ret: { dir: oracledb.BINDOUT }
};
cy.db(sql, binds).should(r => {
expect(r.outBinds.ret).to.eq(`You Sent ${binds.p1}`);
});
});
This test results in the error
Error: NJS-045: cannot load the oracledb add-on binary for Node.js
My workaround isn't ideal.
it('Can call a PL/SQL function with bind variables', function() {
let sql;
let binds;
sql = `BEGIN
:ret := test_data_management_pkg.func_test(:p1);
END;`;
binds = {
p1: 'Something',
ret: { dir: 'out' }
};
cy.db(sql, binds).should(r => {
expect(r.outBinds.ret).to.eq(`You Sent ${binds.p1}`);
});
});
I am using my own notation for bind directions and having to resolve them to the proper values at a later point just before the connection is established by the node-oracledb driver.
var oracle = require('oracledb');
var dbconfig = require('../../cypress.json').db;
oracle.autoCommit = true;
const bindMap = {
"in": oracle.BIND_IN,
"out": oracle.BIND_OUT,
"inout": oracle.BIND_INOUT
};
const replaceBinds = binds => {
for (const bind in binds) {
if (binds[bind].dir) {
binds[bind].dir = bindMap[binds[bind].dir];
}
}
return binds;
};