oracle port config #496

This commit is contained in:
Jan Prochazka
2023-02-26 10:01:53 +01:00
parent 622773fccd
commit 7a606cf8ef
2 changed files with 34 additions and 89 deletions

View File

@@ -52,52 +52,10 @@ const drivers = driverBases.map(driverBase => ({
authType, authType,
socketPath, socketPath,
}) { }) {
let options = null; client = await oracledb.getConnection({
if (engine == 'redshift@dbgate-plugin-oracle') {
let url = databaseUrl;
if (url && url.startsWith('jdbc:redshift://')) {
url = url.substring('jdbc:redshift://'.length);
}
if (user && password) {
url = `oracle://${user}:${password}@${url}`;
} else if (user) {
url = `oracle://${user}@${url}`;
} else {
url = `oracle://${url}`;
}
options = {
connectionString: url,
};
} else {
options = useDatabaseUrl
? {
connectionString: databaseUrl,
}
: {
host: authType == 'socket' ? socketPath || driverBase.defaultSocketPath : server,
port: authType == 'socket' ? null : port,
user, user,
password, password,
database: database || 'oracle', connectString: useDatabaseUrl ? databaseUrl : port ? `${server}:${port}` : server,
ssl,
};
}
// console.log('OPTIONS', options);
/*
const client = new pg.Client(options);
await client.connect();
if (isReadOnly) {
await this.query(client, 'SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY');
}
*/
client = await oracledb.getConnection( {
user : options.user,
password : options.password,
connectString : options.host
}); });
return client; return client;
}, },
@@ -112,21 +70,18 @@ const drivers = driverBases.map(driverBase => ({
columns: [], columns: [],
}; };
} }
try { try {
//console.log('sql3', sql); //console.log('sql3', sql);
const res = await client.execute(sql); const res = await client.execute(sql);
//console.log('res', res); //console.log('res', res);
const columns = extractOracleColumns(res.metaData); const columns = extractOracleColumns(res.metaData);
//console.log('columns', columns); //console.log('columns', columns);
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns }; return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
} } catch (err) {
catch(err) {
console.log('Error query', err, sql); console.log('Error query', err, sql);
} } finally {
finally {
//console.log('finally', sql); //console.log('finally', sql);
} }
}, },
stream(client, sql, options) { stream(client, sql, options) {
/* /*
@@ -200,12 +155,11 @@ finally {
}); });
options.done(); options.done();
}); });
query.on('close', function() { query.on('close', function () {
//console.log("stream 'close' event"); //console.log("stream 'close' event");
// The underlying ResultSet has been closed, so the connection can now // The underlying ResultSet has been closed, so the connection can now
// be closed, if desired. Note: do not close connections on 'end'. // be closed, if desired. Note: do not close connections on 'end'.
//resolve(rowcount); //resolve(rowcount);
;
}); });
//}); //});
@@ -215,7 +169,7 @@ finally {
}, },
async getVersion(client) { async getVersion(client) {
//const { rows } = await this.query(client, "SELECT banner as version FROM v$version WHERE banner LIKE 'Oracle%'"); //const { rows } = await this.query(client, "SELECT banner as version FROM v$version WHERE banner LIKE 'Oracle%'");
const { rows } = await this.query(client, "SELECT version as \"version\" FROM v$instance"); const { rows } = await this.query(client, 'SELECT version as "version" FROM v$instance');
const { version } = rows[0]; const { version } = rows[0];
const isCockroach = false; //version.toLowerCase().includes('cockroachdb'); const isCockroach = false; //version.toLowerCase().includes('cockroachdb');
@@ -245,7 +199,7 @@ finally {
}; };
}, },
async readQuery(client, sql, structure) { async readQuery(client, sql, structure) {
/* /*
const query = new pg.Query({ const query = new pg.Query({
text: sql, text: sql,
rowMode: 'array', rowMode: 'array',
@@ -301,7 +255,7 @@ finally {
return createBulkInsertStreamBase(this, stream, pool, name, options); return createBulkInsertStreamBase(this, stream, pool, name, options);
}, },
async listDatabases(client) { async listDatabases(client) {
const { rows } = await this.query(client, 'SELECT instance_name AS \"name\" FROM v$instance'); const { rows } = await this.query(client, 'SELECT instance_name AS "name" FROM v$instance');
return rows; return rows;
}, },
@@ -319,7 +273,7 @@ finally {
}, },
})); }));
drivers.initialize = (dbgateEnv) => { drivers.initialize = dbgateEnv => {
if (dbgateEnv.nativeModules && dbgateEnv.nativeModules.oracledb) { if (dbgateEnv.nativeModules && dbgateEnv.nativeModules.oracledb) {
oracledb = dbgateEnv.nativeModules.oracledb(); oracledb = dbgateEnv.nativeModules.oracledb();
} }

View File

@@ -118,11 +118,7 @@ const oracleDriverBase = {
return ['databaseUrl', 'isReadOnly'].includes(field); return ['databaseUrl', 'isReadOnly'].includes(field);
} }
return ( return ['user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly', 'server', 'port'].includes(field);
['authType', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field) ||
(values.authType == 'socket' && ['socketPath'].includes(field)) ||
(values.authType != 'socket' && ['server', 'port'].includes(field))
);
}, },
beforeConnectionSave: connection => { beforeConnectionSave: connection => {
@@ -166,17 +162,13 @@ $$ LANGUAGE plpgsql;`,
}, },
]; ];
}, },
authTypeLabel: 'Connection mode',
defaultAuthTypeName: 'hostPort',
defaultSocketPath: '/var/run/oracledb',
}; };
/** @type {import('dbgate-types').EngineDriver} */ /** @type {import('dbgate-types').EngineDriver} */
const oracleDriver = { const oracleDriver = {
...oracleDriverBase, ...oracleDriverBase,
engine: 'oracle@dbgate-plugin-oracle', engine: 'oracle@dbgate-plugin-oracle',
title: 'OracleDB', title: 'OracleDB (BETA)',
defaultPort: 1521, defaultPort: 1521,
dialect: { dialect: {
...dialect, ...dialect,
@@ -198,5 +190,4 @@ const oracleDriver = {
}, },
}; };
module.exports = [oracleDriver]; module.exports = [oracleDriver];