-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Added Oracle database connector with node-oracledb thin mode #5162
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
Closed
anjumsohail
wants to merge
10
commits into
Mintplex-Labs:master
from
anjumsohail:feature/oracle-thin-support
+133
β4
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
19b4c68
Add Oracle database connector with node-oracledb thin mode
anjumsohail 7a067ea
Delete extras/build.txt
anjumsohail cc72fe3
Delete extras/oracle-support.md
anjumsohail b7244e2
Clean up comments in system.js
anjumsohail d2b2562
Delete frontend/src/pages/Admin/Agents/SQLConnectorSelection/icons/orβ¦
anjumsohail ff966d1
Uploaded Resized 330x330 Oracle Logo
anjumsohail 3d3d3fb
Refactor Oracle connector to load driver on demand
anjumsohail 93d6e2d
Delete README.md
anjumsohail 77ed7d6
Restore README.md to original state from Base Repository
anjumsohail cefc134
Merge branch 'Mintplex-Labs:master' into feature/oracle-thin-support
anjumsohail File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+9.98 KB
frontend/src/pages/Admin/Agents/SQLConnectorSelection/icons/oracle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
server/utils/agents/aibitat/plugins/sql-agent/SQLConnectors/Oracle.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
|
|
||
|
|
||
| const { ConnectionStringParser } = require("./utils"); | ||
|
|
||
| // -- oracledb.initOracleClient({libDir: "/opt/oracle/instantclient_23_26",}); | ||
| // Thin mode: DO NOT call initOracleClient() | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| class OracleConnector { | ||
| #connected = false; | ||
| database_id = ""; | ||
|
|
||
| constructor( | ||
| config = { | ||
| connectionString: null, | ||
| } | ||
| ) { | ||
| // Load the Oracle driver on demand when this constructor is called | ||
| this.oracledb = require("oracledb"); | ||
|
|
||
| // Set global output format once (will be set each time an instance is created, | ||
| // but that's harmless due to caching) | ||
| this.oracledb.outFormat = this.oracledb.OUT_FORMAT_OBJECT; | ||
|
|
||
| // Log thin mode status when an instance is created | ||
| console.log("Oracle driver thin mode:", oracledb.thin); | ||
|
|
||
| this.className = "OracleConnector"; | ||
| this.connectionString = config.connectionString; | ||
| this._client = null; | ||
| this.database_id = this.#parseDatabase(); | ||
| } | ||
|
|
||
| #parseDatabase() { | ||
| const connectionParser = new ConnectionStringParser({ scheme: "oracle" }); | ||
| const parsed = connectionParser.parse(this.connectionString); | ||
| return parsed?.endpoint; // service name | ||
| } | ||
|
|
||
| async connect() { | ||
| const connectionParser = new ConnectionStringParser({ scheme: "oracle" }); | ||
| const parsed = connectionParser.parse(this.connectionString); | ||
|
|
||
| const host = parsed.hosts[0]?.host; | ||
| const port = parsed.hosts[0]?.port || 1521; | ||
| const service = parsed.endpoint; | ||
|
|
||
| this._client = await oracledb.getConnection({ | ||
| user: parsed.username, | ||
| password: parsed.password, | ||
| connectString: `${host}:${port}/${service}`, | ||
| }); | ||
|
|
||
| this.#connected = true; | ||
| return this._client; | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} queryString | ||
| * @returns {Promise<import(".").QueryResult>} | ||
| */ | ||
| async runQuery(queryString = "") { | ||
| const result = { rows: [], count: 0, error: null }; | ||
|
|
||
| try { | ||
| if (!this.#connected) await this.connect(); | ||
|
|
||
| const query = await this._client.execute(queryString, [], { | ||
| autoCommit: true, | ||
| }); | ||
|
|
||
| result.rows = query.rows || []; | ||
| result.count = query.rows ? query.rows.length : 0; | ||
| } catch (err) { | ||
| console.log(this.className, err); | ||
| result.error = err.message; | ||
| } finally { | ||
| if (this._client) { | ||
| await this._client.close(); | ||
| this.#connected = false; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| async validateConnection() { | ||
| try { | ||
| const result = await this.runQuery("SELECT 1 FROM DUAL"); | ||
| return { success: !result.error, error: result.error }; | ||
| } catch (error) { | ||
| return { success: false, error: error.message }; | ||
| } | ||
| } | ||
|
|
||
| getTablesSql() { | ||
| return ` | ||
| SELECT table_name | ||
| FROM user_tables | ||
| `; | ||
| } | ||
|
|
||
| getTableSchemaSql(table_name) { | ||
| return ` | ||
| SELECT column_name, data_type | ||
| FROM user_tab_columns | ||
| WHERE table_name = UPPER('${table_name}') | ||
| `; | ||
| } | ||
| } | ||
|
|
||
| module.exports.OracleConnector = OracleConnector; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PNG needs a white bg and be 330x330px if not already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are made in the Review PR