Integrate with UI
This commit is contained in:
parent
cb661eab34
commit
9273edc794
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
|
@ -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>
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,37 +81,8 @@ module OracleModule {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
class OracleIntegration extends Sql {
|
||||||
const TYPE_MAP = {
|
|
||||||
// TODO: type map
|
|
||||||
}
|
|
||||||
|
|
||||||
const internalQuery = async (connection: Connection, query: SqlQuery): Promise<Result<any> | null>=> {
|
|
||||||
try {
|
|
||||||
const result: Result<any> = await connection.execute(
|
|
||||||
`SELECT manager_id, department_id, department_name
|
|
||||||
FROM departments
|
|
||||||
WHERE manager_id = :id`,
|
|
||||||
[103], // bind value for :id
|
|
||||||
);
|
|
||||||
return result
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
return null
|
|
||||||
} finally {
|
|
||||||
if (connection) {
|
|
||||||
try {
|
|
||||||
await connection.close();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class OracleIntegration extends Sql implements DatasourcePlus {
|
|
||||||
private readonly config: OracleConfig
|
private readonly config: OracleConfig
|
||||||
private readonly client: any
|
|
||||||
public tables: Record<string, Table> = {}
|
public tables: Record<string, Table> = {}
|
||||||
public schemaErrors: Record<string, string> = {}
|
public schemaErrors: Record<string, string> = {}
|
||||||
|
|
||||||
|
@ -131,76 +91,55 @@ module OracleModule {
|
||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
getConnection = async (): Promise<Connection> => {
|
private query = async (query: SqlQuery): Promise<Result<any>> => {
|
||||||
|
let connection
|
||||||
|
try {
|
||||||
|
connection = await this.getConnection()
|
||||||
|
|
||||||
|
const options : ExecuteOptions = { autoCommit: true }
|
||||||
|
const result: Result<any> = await connection.execute(query.sql, [], options)
|
||||||
|
|
||||||
|
return result
|
||||||
|
} finally {
|
||||||
|
if (connection) {
|
||||||
|
try {
|
||||||
|
await connection.close();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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) {
|
async update(query: SqlQuery | string) {
|
||||||
// const response = await internalQuery(this.client, getSqlQuery(query))
|
const response = await this.query(getSqlQuery(query))
|
||||||
// return response.rows
|
return response.rows && response.rows.length ? response.rows : [{ updated: true }]
|
||||||
// }
|
}
|
||||||
|
|
||||||
// async update(query: SqlQuery | string) {
|
async delete(query: SqlQuery | string) {
|
||||||
// const response = await internalQuery(this.client, getSqlQuery(query))
|
const response = await this.query(getSqlQuery(query))
|
||||||
// return response.rows.length ? response.rows : [{ updated: true }]
|
return response.rows && response.rows.length ? response.rows : [{ deleted: 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 }]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue