Merge pull request #10590 from Budibase/feature/datasource-testConnection-resp
Refactor datasource testConnection to use a simple type.
This commit is contained in:
commit
bc21484223
17 changed files with 80 additions and 40 deletions
|
@ -140,7 +140,7 @@ export async function verify(
|
|||
} else {
|
||||
ctx.body = {
|
||||
connected: false,
|
||||
error: response.error
|
||||
error: response.error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ const SCHEMA: Integration = {
|
|||
"Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
|
||||
friendlyName: "Airtable",
|
||||
type: "Spreadsheet",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
apiKey: {
|
||||
type: DatasourceFieldType.PASSWORD,
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
QueryType,
|
||||
IntegrationBase,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
|
||||
import { Database, aql } from "arangojs"
|
||||
|
@ -77,12 +78,16 @@ class ArangoDBIntegration implements IntegrationBase {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.client.get()
|
||||
return true
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async read(query: { sql: any }) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
ConnectionInfo,
|
||||
DatasourceFeature,
|
||||
DatasourceFieldType,
|
||||
Document,
|
||||
|
@ -70,12 +71,16 @@ class CouchDBIntegration implements IntegrationBase {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
const result = await this.query("exists", "validation error", {})
|
||||
return result === true
|
||||
response.connected = result === true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async query(
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
QueryType,
|
||||
IntegrationBase,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
|
||||
import AWS from "aws-sdk"
|
||||
|
@ -152,12 +153,16 @@ class DynamoDBIntegration implements IntegrationBase {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
const scanRes = await new AWS.DynamoDB(this.config).listTables().promise()
|
||||
return !!scanRes.$response
|
||||
response.connected = !!scanRes.$response
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async create(query: {
|
||||
|
|
|
@ -21,7 +21,7 @@ const SCHEMA: Integration = {
|
|||
"Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.",
|
||||
friendlyName: "ElasticSearch",
|
||||
type: "Non-relational",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
url: {
|
||||
type: DatasourceFieldType.STRING,
|
||||
|
|
|
@ -19,7 +19,7 @@ const SCHEMA: Integration = {
|
|||
type: "Non-relational",
|
||||
description:
|
||||
"Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud.",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
email: {
|
||||
type: DatasourceFieldType.STRING,
|
||||
|
|
|
@ -65,7 +65,7 @@ const SCHEMA: Integration = {
|
|||
"Create and collaborate on online spreadsheets in real-time and from any device. ",
|
||||
friendlyName: "Google Sheets",
|
||||
type: "Spreadsheet",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
spreadsheetId: {
|
||||
display: "Google Sheet URL",
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
SqlQuery,
|
||||
DatasourcePlus,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
import {
|
||||
getSqlQuery,
|
||||
|
@ -124,12 +125,16 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.connect()
|
||||
return true
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
getBindingIdentifier(): string {
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
QueryType,
|
||||
IntegrationBase,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
import {
|
||||
MongoClient,
|
||||
|
@ -361,12 +362,16 @@ class MongoIntegration implements IntegrationBase {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.connect()
|
||||
return true
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async connect() {
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
TableSchema,
|
||||
DatasourcePlus,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
import {
|
||||
getSqlQuery,
|
||||
|
@ -155,15 +156,19 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
const [result] = await this.internalQuery(
|
||||
{ sql: "SELECT 1+1 AS checkRes" },
|
||||
{ connect: true }
|
||||
)
|
||||
return result?.checkRes == 2
|
||||
response.connected = result?.checkRes == 2
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
getBindingIdentifier(): string {
|
||||
|
|
|
@ -25,12 +25,7 @@ import {
|
|||
ExecuteOptions,
|
||||
Result,
|
||||
} from "oracledb"
|
||||
import {
|
||||
OracleTable,
|
||||
OracleColumn,
|
||||
OracleColumnsResponse,
|
||||
OracleConstraint,
|
||||
} from "./base/types"
|
||||
import { OracleTable, OracleColumn, OracleColumnsResponse } from "./base/types"
|
||||
let oracledb: any
|
||||
try {
|
||||
oracledb = require("oracledb")
|
||||
|
@ -54,7 +49,7 @@ const SCHEMA: Integration = {
|
|||
type: "Relational",
|
||||
description:
|
||||
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
host: {
|
||||
type: DatasourceFieldType.STRING,
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Table,
|
||||
DatasourcePlus,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
import {
|
||||
getSqlQuery,
|
||||
|
@ -153,14 +154,18 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.openConnection()
|
||||
return true
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
} finally {
|
||||
await this.closeConnection()
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
getBindingIdentifier(): string {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
ConnectionInfo,
|
||||
DatasourceFeature,
|
||||
DatasourceFieldType,
|
||||
Integration,
|
||||
|
@ -107,14 +108,18 @@ class RedisIntegration {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.client.ping()
|
||||
return true
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
response.error = e.message as string
|
||||
} finally {
|
||||
await this.disconnect()
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
IntegrationBase,
|
||||
DatasourceFieldType,
|
||||
DatasourceFeature,
|
||||
ConnectionInfo,
|
||||
} from "@budibase/types"
|
||||
|
||||
import AWS from "aws-sdk"
|
||||
|
@ -168,12 +169,16 @@ class S3Integration implements IntegrationBase {
|
|||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
const buckets = await this.client.listBuckets().promise()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
try {
|
||||
await this.client.listBuckets().promise()
|
||||
response.connected = true
|
||||
} catch (e: any) {
|
||||
response.error = e.message as string
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async create(query: {
|
||||
|
|
|
@ -21,7 +21,7 @@ const SCHEMA: Integration = {
|
|||
"Snowflake is a solution for data warehousing, data lakes, data engineering, data science, data application development, and securely sharing and consuming shared data.",
|
||||
friendlyName: "Snowflake",
|
||||
type: "Relational",
|
||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||
features: [],
|
||||
datasource: {
|
||||
account: {
|
||||
type: "string",
|
||||
|
|
|
@ -128,17 +128,17 @@ export interface Integration {
|
|||
extra?: ExtraQueryConfig
|
||||
}
|
||||
|
||||
export type ConnectionInfo = {
|
||||
connected: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface IntegrationBase {
|
||||
create?(query: any): Promise<any[] | any>
|
||||
read?(query: any): Promise<any[] | any>
|
||||
update?(query: any): Promise<any[] | any>
|
||||
delete?(query: any): Promise<any[] | any>
|
||||
testConnection?(): Promise<
|
||||
| boolean
|
||||
| {
|
||||
error: string
|
||||
}
|
||||
>
|
||||
testConnection?(): Promise<ConnectionInfo>
|
||||
}
|
||||
|
||||
export interface DatasourcePlus extends IntegrationBase {
|
||||
|
|
Loading…
Reference in a new issue