Skip to content

Commit

Permalink
Fix driver options specified with .options() method being ignored f…
Browse files Browse the repository at this point in the history
…or oracledb dialect (#5123)

Co-authored-by: Matt Bailey <bailey.matthewr@gmail.com>
  • Loading branch information
Kytech and baileymatthewr committed Jul 19, 2023
1 parent daeec25 commit 5ececd3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/dialects/oracledb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Client_Oracledb extends Client_Oracle {
_query(connection, obj) {
if (!obj.sql) throw new Error('The query is empty');

const options = { autoCommit: false };
const options = Object.assign({}, obj.options, { autoCommit: false });
if (obj.method === 'select') {
options.resultSet = true;
}
Expand Down
52 changes: 32 additions & 20 deletions test/integration2/dialects/oracledb.spec.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
const { expect } = require('chai');
const { getAllDbs, getKnexForDb } = require('../util/knex-instance-provider');
const { getDriverName } = require('../../util/db-helpers');

describe('Oracledb dialect', () => {
describe('Connection configuration', () => {
const dbs = getAllDbs().filter((db) => db === 'oracledb');
const dbs = getAllDbs().filter((db) => db === 'oracledb');

dbs.forEach((db) => {
describe(db, () => {
let knex;
before(() => {
knex = getKnexForDb(db, {
connection: {
user: 'user',
password: 'password',
connectString: 'connect-string',
externalAuth: true,
host: 'host',
database: 'database',
},
});
});
dbs.forEach((db) => {
describe(db, () => {
let knex;
before(() => {
knex = getKnexForDb(db);
});

after(() => {
return knex.destroy();
});
after(() => {
return knex.destroy();
});

describe('Connection configuration', () => {
describe('#4869 inserting Buffer', async () => {
it('.toSQL().toNative() generates correct sql and bindings for INSERT of Buffer', async () => {
const b = Buffer.from('hello', 'utf-8');
Expand All @@ -40,6 +32,26 @@ describe('Oracledb dialect', () => {
});
});
});

describe('Client', () => {
describe('#5123 options not passed to driver', () => {
it('should pass values supplied to .options() to the driver', async () => {
const oracleDriver = require(getDriverName(knex));

const query = knex
.raw("select DATE '2022-05-25' as TEST_DATE from dual")
.options({
fetchInfo: { TEST_DATE: { type: oracleDriver.STRING } },
});
const [{ TEST_DATE: testDate }] = await query;

expect(query.toSQL().options).to.deep.equal({
fetchInfo: { TEST_DATE: { type: oracleDriver.STRING } },
});
expect(testDate).to.be.a('string');
});
});
});
});
});
});
1 change: 1 addition & 0 deletions test/util/db-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function isOneOfDbs(knex, supportedDbs) {
}

module.exports = {
getDriverName,
isOneOfDbs,
isCockroachDB,
isMysql,
Expand Down

0 comments on commit 5ececd3

Please sign in to comment.