From ca4d976a769a86402c935dc1d7fdcab70958b870 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 9 Jun 2021 16:55:58 +0100 Subject: [PATCH] plus datasource schema --- .../server/src/api/controllers/datasource.js | 2 +- packages/server/src/db/utils.js | 10 +++-- packages/server/src/integrations/index.js | 3 ++ .../server/src/integrations/plus/postgres.js | 44 ++++++++++++++++++- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 786fa14769..9aef43ecd6 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -66,7 +66,7 @@ exports.find = async function (ctx) { exports.plus = async function (ctx) { const db = new CouchDB(ctx.appId) - const PlusConnector = plusIntegrations[ctx.request.body.source] + const PlusConnector = plusIntegrations[ctx.request.body.source].integration const connector = new PlusConnector(ctx.request.body) await connector.init() diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index dd5cb974e0..ecae8a1b27 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -284,10 +284,12 @@ exports.getWebhookParams = (webhookId = null, otherProps = {}) => { * Generates a new datasource ID. * @returns {string} The new datasource ID which the webhook doc can be stored under. */ -exports.generateDatasourceID = ({ plus = false }) => { - return `${ - plus ? DocumentTypes.DATASOURCE_PLUS : DocumentTypes.DATASOURCE - }${SEPARATOR}${newid()}` +exports.generateDatasourceID = options => { + let id = DocumentTypes.DATASOURCE + if (options && options.plus) { + id = DocumentTypes.DATASOURCE_PLUS + } + return `${id}${SEPARATOR}${newid()}` } /** diff --git a/packages/server/src/integrations/index.js b/packages/server/src/integrations/index.js index 4999f0c867..6916987960 100644 --- a/packages/server/src/integrations/index.js +++ b/packages/server/src/integrations/index.js @@ -9,6 +9,8 @@ const airtable = require("./airtable") const mysql = require("./mysql") const arangodb = require("./arangodb") const rest = require("./rest") +// Plus +const postgresPlus = require("../integrations/plus/postgres") const DEFINITIONS = { POSTGRES: postgres.schema, @@ -22,6 +24,7 @@ const DEFINITIONS = { MYSQL: mysql.schema, ARANGODB: arangodb.schema, REST: rest.schema, + POSTGRES_PLUS: postgresPlus.schema, } const INTEGRATIONS = { diff --git a/packages/server/src/integrations/plus/postgres.js b/packages/server/src/integrations/plus/postgres.js index 2606195ff3..87be332019 100644 --- a/packages/server/src/integrations/plus/postgres.js +++ b/packages/server/src/integrations/plus/postgres.js @@ -1,5 +1,6 @@ const { Pool } = require("pg") const { FieldTypes } = require("../../constants") +const { FIELD_TYPES } = require("../Integration") const TYPE_MAP = { text: FieldTypes.LONGFORM, @@ -13,6 +14,44 @@ const TYPE_MAP = { boolean: FieldTypes.BOOLEAN, } +const SCHEMA = { + friendlyName: "PostgreSQL", + description: + "PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.", + datasource: { + host: { + type: FIELD_TYPES.STRING, + default: "localhost", + required: true, + }, + port: { + type: FIELD_TYPES.NUMBER, + required: true, + default: 5432, + }, + database: { + type: FIELD_TYPES.STRING, + default: "postgres", + required: true, + }, + user: { + type: FIELD_TYPES.STRING, + default: "root", + required: true, + }, + password: { + type: FIELD_TYPES.PASSWORD, + default: "root", + required: true, + }, + ssl: { + type: FIELD_TYPES.BOOLEAN, + default: false, + required: false, + }, + }, +} + class PostgresPlus { static pool COLUMNS_SQL = @@ -52,4 +91,7 @@ class PostgresPlus { } } -module.exports = PostgresPlus +module.exports = { + schema: SCHEMA, + integration: PostgresPlus, +}