diff --git a/packages/server/scripts/integrations/oracle-express/docker-compose.yml b/packages/server/scripts/integrations/oracle-express/docker-compose.yml new file mode 100644 index 0000000000..5cd5e02f81 --- /dev/null +++ b/packages/server/scripts/integrations/oracle-express/docker-compose.yml @@ -0,0 +1,19 @@ +# For more information see: +# https://container-registry.oracle.com/ +# - Database > Express +version: "3.8" +services: + db: + container_name: oracle-xe + platform: linux/x86_64 + image: container-registry.oracle.com/database/express:18.4.0-xe + environment: + ORACLE_PWD: oracle + ports: + - 1521:1521 + - 5500:5500 + volumes: + - oracle_data:/opt/oracle/oradata + +volumes: + oracle_data: diff --git a/packages/server/scripts/integrations/oracle-express/reset.sh b/packages/server/scripts/integrations/oracle-express/reset.sh new file mode 100755 index 0000000000..32778bd11f --- /dev/null +++ b/packages/server/scripts/integrations/oracle-express/reset.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker-compose down +docker volume prune -f diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts new file mode 100644 index 0000000000..efd9ad1310 --- /dev/null +++ b/packages/server/src/integrations/oracle.ts @@ -0,0 +1,124 @@ +import { + Integration, + DatasourceFieldTypes, + QueryTypes, + QueryJson, + SqlQuery, +} from "../definitions/datasource" +import { Table } from "../definitions/common" +import { getSqlQuery } from "./utils" +import { DatasourcePlus } from "./base/datasourcePlus" + +module OracleModule { + // TODO: oracle js lib + // const connection = require("oracle") + const Sql = require("./base/sql") + const { FieldTypes } = require("../constants") + const { + buildExternalTableId, + convertType, + finaliseExternalTables, + } = require("./utils") + + interface OracleConfig { + // TODO: Connection config + } + + const SCHEMA: Integration = { + docs: "https://docs", + // plus: true, + friendlyName: "Oracle", + description: "description", + datasource: { + // TODO: datasource config + }, + query: { + // TODO: query config + }, + } + + const TYPE_MAP = { + // TODO: type map + } + + async function internalQuery(client: any, query: SqlQuery) { + // TODO: Use oracle lib to run query + const rows = [] + + return rows + } + + class OracleIntegration extends Sql implements DatasourcePlus { + private readonly config: OracleConfig + private readonly client: any + public tables: Record = {} + public schemaErrors: Record = {} + + constructor(config: OracleConfig) { + super("oracle") + this.config = config + //todo init client + } + + /** + * Fetches the tables from the postgres table and assigns them to the datasource. + * @param {*} datasourceId - datasourceId to fetch + * @param entities - the tables that are to be built + */ + async buildSchema(datasourceId: string, entities: Record) { + // get the tables + const tables: { [key: string]: Table } = {} + + // get the base table data + // { + // _id: buildExternalTableId(datasourceId, tableName), + // primary: tableKeys[tableName] || [], + // name: tableName, + // schema: {}, + // } + + // get the schema + // { + // autocolumn: isAuto, + // name: columnName, + // type, + // } + + const final = finaliseExternalTables(tables, entities) + this.tables = final.tables + this.schemaErrors = final.errors + } + + // async create(query: SqlQuery | string) { + // const response = await internalQuery(this.client, getSqlQuery(query)) + // return response.rows.length ? response.rows : [{ created: true }] + // } + + // async read(query: SqlQuery | string) { + // const response = await internalQuery(this.client, getSqlQuery(query)) + // return response.rows + // } + + // async update(query: SqlQuery | string) { + // const response = await internalQuery(this.client, getSqlQuery(query)) + // return response.rows.length ? response.rows : [{ updated: true }] + // } + + // async delete(query: SqlQuery | string) { + // const response = await internalQuery(this.client, getSqlQuery(query)) + // return response.rows.length ? response.rows : [{ deleted: true }] + // } + + async query(json: QueryJson) { + const operation = this._operation(json).toLowerCase() + const input = this._query(json) + const response = await internalQuery(this.client, input) + return response.rows.length ? response.rows : [{ [operation]: true }] + } + } + + module.exports = { + schema: SCHEMA, + integration: OracleIntegration, + } +}