1
0
Fork 0
mirror of synced 2024-07-01 12:30:41 +12:00

Integrate with UI

This commit is contained in:
Rory Powell 2021-11-08 22:08:47 +00:00
parent ab1fb07f86
commit 5257fe7bf7
5 changed files with 62 additions and 104 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View file

@ -0,0 +1,16 @@
<script>
export let width = "18"
export let height = "18"
import OracleLogo from "assets/oracle.png"
</script>
<div class>
<img {height} {width} src={OracleLogo} alt="oracle logo" />
</div>
<style>
img {
padding-top: 1px;
}
</style>

View file

@ -10,6 +10,7 @@ import MySQL from "./MySQL.svelte"
import ArangoDB from "./ArangoDB.svelte" import ArangoDB from "./ArangoDB.svelte"
import Rest from "./Rest.svelte" import Rest from "./Rest.svelte"
import Budibase from "./Budibase.svelte" import Budibase from "./Budibase.svelte"
import Oracle from "./Oracle.svelte"
export default { export default {
BUDIBASE: Budibase, BUDIBASE: Budibase,
@ -24,4 +25,5 @@ export default {
MYSQL: MySQL, MYSQL: MySQL,
ARANGODB: ArangoDB, ARANGODB: ArangoDB,
REST: Rest, REST: Rest,
ORACLE: Oracle,
} }

View file

@ -27,6 +27,7 @@ export const IntegrationNames = {
SQL_SERVER: "SQL Server", SQL_SERVER: "SQL Server",
AIRTABLE: "Airtable", AIRTABLE: "Airtable",
ARANGODB: "ArangoDB", ARANGODB: "ArangoDB",
ORACLE: "Oracle",
} }
// fields on the user table that cannot be edited // fields on the user table that cannot be edited

View file

@ -2,26 +2,16 @@ import {
Integration, Integration,
DatasourceFieldTypes, DatasourceFieldTypes,
QueryTypes, QueryTypes,
QueryJson,
SqlQuery, SqlQuery,
} from "../definitions/datasource" } from "../definitions/datasource"
import { Table } from "../definitions/common" import { Table } from "../definitions/common"
import { getSqlQuery } from "./utils" import { getSqlQuery } from "./utils"
import { DatasourcePlus } from "./base/datasourcePlus" import oracledb, { ExecuteOptions, Result } from "oracledb"
import oracledb, { Result } from "oracledb" import { Connection, ConnectionAttributes } from "oracledb"
import { Connection } from "oracledb"
import Sql from "./base/sql" import Sql from "./base/sql"
import { FieldTypes } from "../constants"
import {
buildExternalTableId,
convertType,
finaliseExternalTables
} from "./utils"
module OracleModule { module OracleModule {
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT; oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
interface OracleConfig { interface OracleConfig {
host: string host: string
port: number port: number
@ -34,10 +24,9 @@ module OracleModule {
} }
const SCHEMA: Integration = { const SCHEMA: Integration = {
docs: "https://docs", docs: "https://github.com/oracle/node-oracledb",
// plus: true,
friendlyName: "Oracle", friendlyName: "Oracle",
description: "description", description: "Oracle Database is an object-relational database management system developed by Oracle Corporation",
datasource: { datasource: {
host: { host: {
type: DatasourceFieldTypes.STRING, type: DatasourceFieldTypes.STRING,
@ -92,23 +81,25 @@ module OracleModule {
}, },
}, },
} }
class OracleIntegration extends Sql {
private readonly config: OracleConfig
public tables: Record<string, Table> = {}
public schemaErrors: Record<string, string> = {}
const TYPE_MAP = { constructor(config: OracleConfig) {
// TODO: type map super("oracle")
this.config = config
} }
const internalQuery = async (connection: Connection, query: SqlQuery): Promise<Result<any> | null>=> { private query = async (query: SqlQuery): Promise<Result<any>> => {
let connection
try { try {
const result: Result<any> = await connection.execute( connection = await this.getConnection()
`SELECT manager_id, department_id, department_name
FROM departments const options : ExecuteOptions = { autoCommit: true }
WHERE manager_id = :id`, const result: Result<any> = await connection.execute(query.sql, [], options)
[103], // bind value for :id
);
return result return result
} catch (err) {
console.error(err);
return null
} finally { } finally {
if (connection) { if (connection) {
try { try {
@ -120,87 +111,35 @@ module OracleModule {
} }
} }
class OracleIntegration extends Sql implements DatasourcePlus { private getConnection = async (): Promise<Connection> => {
private readonly config: OracleConfig
private readonly client: any
public tables: Record<string, Table> = {}
public schemaErrors: Record<string, string> = {}
constructor(config: OracleConfig) {
super("oracle")
this.config = config
}
getConnection = async (): Promise<Connection> => {
//connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SID= ORCL)))" //connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SID= ORCL)))"
const connectString = `${this.config.host}:${this.config.port || 1521}/${this.config.database}` const connectString = `${this.config.host}:${this.config.port || 1521}/${this.config.database}`
const config = { const attributes: ConnectionAttributes = {
user: this.config.user, user: this.config.user,
password: this.config.user, password: this.config.user,
connectString connectString,
} }
return oracledb.getConnection(config); return oracledb.getConnection(attributes);
} }
/** async create(query: SqlQuery | string) {
* Fetches the tables from the postgres table and assigns them to the datasource. const response = await this.query(getSqlQuery(query))
* @param {*} datasourceId - datasourceId to fetch return response.rows && response.rows.length ? response.rows : [{ created: true }]
* @param entities - the tables that are to be built
*/
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
// 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) { async read(query: SqlQuery | string) {
// const response = await internalQuery(this.client, getSqlQuery(query)) const response = await this.query(getSqlQuery(query))
// return response.rows.length ? response.rows : [{ created: true }] return response.rows
// }
// 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 connection = await this.getConnection()
const result = await internalQuery(connection, input)
if (result && result.rows && result.rows.length) {
return result.rows
} else {
return [{ [operation]: true }]
} }
async update(query: SqlQuery | string) {
const response = await this.query(getSqlQuery(query))
return response.rows && response.rows.length ? response.rows : [{ updated: true }]
}
async delete(query: SqlQuery | string) {
const response = await this.query(getSqlQuery(query))
return response.rows && response.rows.length ? response.rows : [{ deleted: true }]
} }
} }