From f1b9490f224d2229760a5db13a94a51c1e91d8dd Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 12 Jan 2022 17:55:28 +0000 Subject: [PATCH] Adding method for client/builder to detect that a table supports SQL filtering. --- packages/server/src/api/controllers/table/index.js | 3 ++- packages/server/src/api/controllers/table/utils.js | 5 ++++- packages/server/src/integrations/utils.ts | 11 ++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/table/index.js b/packages/server/src/api/controllers/table/index.js index abbb4d6ff9..15e869fc75 100644 --- a/packages/server/src/api/controllers/table/index.js +++ b/packages/server/src/api/controllers/table/index.js @@ -2,7 +2,7 @@ const CouchDB = require("../../../db") const internal = require("./internal") const external = require("./external") const csvParser = require("../../../utilities/csvParser") -const { isExternalTable } = require("../../../integrations/utils") +const { isExternalTable, isSQL } = require("../../../integrations/utils") const { getTableParams, getDatasourceParams, @@ -49,6 +49,7 @@ exports.fetch = async function (ctx) { ...entity, type: "external", sourceId: row.doc._id, + sql: isSQL(row.doc), })) }) diff --git a/packages/server/src/api/controllers/table/utils.js b/packages/server/src/api/controllers/table/utils.js index e4086e8071..459566ce91 100644 --- a/packages/server/src/api/controllers/table/utils.js +++ b/packages/server/src/api/controllers/table/utils.js @@ -12,6 +12,7 @@ const { USERS_TABLE_SCHEMA, SwitchableTypes } = require("../../../constants") const { isExternalTable, breakExternalTableId, + isSQL, } = require("../../../integrations/utils") const { getViews, saveView } = require("../view/utils") const viewTemplate = require("../view/viewBuilder") @@ -242,7 +243,9 @@ exports.getTable = async (appId, tableId) => { const db = new CouchDB(appId) if (isExternalTable(tableId)) { let { datasourceId, tableName } = breakExternalTableId(tableId) - return exports.getExternalTable(appId, datasourceId, tableName) + const datasource = await db.get(datasourceId) + const table = await exports.getExternalTable(appId, datasourceId, tableName) + return { ...table, sql: isSQL(datasource) } } else { return db.get(tableId) } diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 97380b1b5b..b1b1faf776 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -1,6 +1,6 @@ -import { SqlQuery } from "../definitions/datasource" +import { SourceNames, SqlQuery } from "../definitions/datasource" import { Datasource, Table } from "../definitions/common" -import { SourceNames } from "../definitions/datasource" + const { DocumentTypes, SEPARATOR } = require("../db/utils") const { FieldTypes, @@ -131,7 +131,12 @@ export function isSQL(datasource: Datasource): boolean { if (!datasource || !datasource.source) { return false } - const SQL = [SourceNames.POSTGRES, SourceNames.SQL_SERVER, SourceNames.MYSQL] + const SQL = [ + SourceNames.POSTGRES, + SourceNames.SQL_SERVER, + SourceNames.MYSQL, + SourceNames.ORACLE, + ] return SQL.indexOf(datasource.source) !== -1 }