Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oracle): added support for connectString #15042

Merged
merged 6 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 11 additions & 40 deletions src/dialects/oracle/connection-manager.js
Expand Up @@ -59,32 +59,19 @@ export class OracleConnectionManager extends AbstractConnectionManager {
* @returns {Promise<Connection>}
* @private
*/
checkConfigObject(config) {
// A connectString should be defined
if (config.database.length === 0) {
let errorToThrow =
'The database cannot be blank, you must specify the database name (which correspond to the service name';
errorToThrow += '\n from tnsnames.ora : (HOST = mymachine.example.com)(PORT = 1521)(SERVICE_NAME = orcl)';
throw new Error(errorToThrow);
buildConnectString(config) {
if (!config.host || config.host.length === 0)
return config.database;
let connectString = config.host;
if (config.port && config.port > 0) {
connectString += `:${config.port}`;
} else {
connectString += ':1521';
}

if (!config.host || config.host.length === 0) {
throw new Error('You have to specify the host');
}

// The connectString has a special format, we check it
// ConnectString format is : host:[port]/service_name
if (config.database.indexOf('/') === -1) {
let connectString = config.host;

if (config.port && config.port !== 0) {
connectString += `:${config.port}`;
} else {
connectString += ':1521'; //Default port number
}
if (config.database && config.database.length > 0) {
connectString += `/${config.database}`;
hjamil-24 marked this conversation as resolved.
Show resolved Hide resolved
config.database = connectString;
}
return connectString;
}

// Expose this as a method so that the parsing may be updated when the user has added additional, custom types
Expand All @@ -108,30 +95,14 @@ export class OracleConnectionManager extends AbstractConnectionManager {
async connect(config) {
const connectionConfig = {
user: config.username,
host: config.host,
port: config.port,
database: config.database,
password: config.password,
externalAuth: config.externalAuth,
stmtCacheSize: 0,
connectString: config.database,
connectString: this.buildConnectString(config),
...config.dialectOptions
};

try {
// Check the config object
this.checkConfigObject(connectionConfig);

// We assume that the database has been correctly formed
connectionConfig.connectString = connectionConfig.database;

// We check if there are dialect options
if (config.dialectOptions) {
Object.keys(config.dialectOptions).forEach(key => {
connectionConfig[key] = config.dialectOptions[key];
});
}

const connection = await this.lib.getConnection(connectionConfig);
// Setting the sequelize database version to Oracle DB server version to remove the roundtrip for DB version query
this.sequelize.options.databaseVersion = semver.coerce(connection.oracleServerVersionString).version;
Expand Down
15 changes: 15 additions & 0 deletions test/integration/dialects/oracle/connection-manager.test.js
@@ -0,0 +1,15 @@
'use strict';

const config = require('../../../config/config.js').oracle;
const Support = require('../../support');
const dialect = Support.getTestDialect();

if (dialect === 'oracle') {
describe('[Oracle Specific] Connection Manager', () => {
it('connect string authentication using connection Descriptor', async () => {
const connDesc = `(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=${config.host})(PORT=${config.port}))(CONNECT_DATA=(SERVICE_NAME=${config.database})))`;
const sequelize = Support.createSequelizeInstance( { dialectOptions: { connectString: connDesc } });
sequelize.authenticate().should.be.ok;
ephys marked this conversation as resolved.
Show resolved Hide resolved
});
});
}