Merge pull request #10590 from Budibase/feature/datasource-testConnection-resp

Refactor datasource testConnection to use a simple type.
This commit is contained in:
Adria Navarro 2023-05-15 18:48:17 +02:00 committed by GitHub
commit bc21484223
17 changed files with 80 additions and 40 deletions

View File

@ -140,7 +140,7 @@ export async function verify(
} else {
ctx.body = {
connected: false,
error: response.error
error: response.error,
}
}
}

View File

@ -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,

View File

@ -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 }) {

View File

@ -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(

View File

@ -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: {

View File

@ -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,

View File

@ -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,

View File

@ -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",

View File

@ -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 {

View File

@ -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() {

View File

@ -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 {

View File

@ -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,

View File

@ -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 {

View File

@ -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() {

View File

@ -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: {

View File

@ -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",

View File

@ -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 {