From 0bd18a2832c886e433f6cc7d1ce36b992c8b7fbe Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 1 Aug 2024 09:34:56 +0100 Subject: [PATCH] wip trigger support --- .../server/src/integrations/base/types.ts | 8 +++++++ packages/server/src/integrations/oracle.ts | 21 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/server/src/integrations/base/types.ts b/packages/server/src/integrations/base/types.ts index 7144d20206..463d73444b 100644 --- a/packages/server/src/integrations/base/types.ts +++ b/packages/server/src/integrations/base/types.ts @@ -104,6 +104,14 @@ export interface OracleColumnsResponse { SEARCH_CONDITION: null | string } +export interface OracleTriggersResponse { + TABLE_NAME: string + TRIGGER_NAME: string + TRIGGER_TYPE: string + TRIGGERING_EVENT: string + TRIGGER_BODY: string +} + /** * An oracle constraint */ diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index 691c5167a7..956526e8cf 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -31,7 +31,12 @@ import oracledb, { ExecuteOptions, Result, } from "oracledb" -import { OracleTable, OracleColumn, OracleColumnsResponse } from "./base/types" +import { + OracleTable, + OracleColumn, + OracleColumnsResponse, + OracleTriggersResponse, +} from "./base/types" import { sql } from "@budibase/backend-core" const Sql = sql.Sql @@ -111,7 +116,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { private readonly config: OracleConfig private index: number = 1 - private readonly COLUMNS_SQL = ` + private static readonly COLUMNS_SQL = ` SELECT tabs.table_name, cols.column_name, @@ -139,6 +144,11 @@ class OracleIntegration extends Sql implements DatasourcePlus { (cons.status = 'ENABLED' OR cons.status IS NULL) ` + + private static readonly TRIGGERS_SQL = ` + SELECT table_name, trigger_name, trigger_type, triggering_event, trigger_body FROM all_triggers WHERE status = 'ENABLED'; + ` + constructor(config: OracleConfig) { super(SqlClient.ORACLE) this.config = config @@ -255,7 +265,10 @@ class OracleIntegration extends Sql implements DatasourcePlus { entities: Record ): Promise { const columnsResponse = await this.internalQuery({ - sql: this.COLUMNS_SQL, + sql: OracleIntegration.COLUMNS_SQL, + }) + const triggersResponse = await this.internalQuery({ + sql: OracleIntegration.TRIGGERS_SQL, }) const oracleTables = this.mapColumns(columnsResponse) @@ -325,7 +338,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { async getTableNames() { const columnsResponse = await this.internalQuery({ - sql: this.COLUMNS_SQL, + sql: OracleIntegration.COLUMNS_SQL, }) return (columnsResponse.rows || []).map(row => row.TABLE_NAME) }