From 1faf920c676a96deafe9e3189aa1872344500a1f Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 12 Oct 2023 16:38:15 +0100 Subject: [PATCH] DatasourcePlus deals exclusively in ExternalTables, reflect that in the types. --- packages/server/src/api/controllers/datasource.ts | 8 ++++++-- packages/server/src/integrations/googlesheets.ts | 5 ++--- packages/server/src/integrations/microsoftSqlServer.ts | 7 +++---- packages/server/src/integrations/mysql.ts | 7 +++---- packages/server/src/integrations/oracle.ts | 5 ++--- packages/server/src/integrations/postgres.ts | 5 ++--- packages/server/src/integrations/utils.ts | 6 +++--- packages/types/src/sdk/datasources.ts | 6 +++--- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index cfbca8eff3..ad0ed06b83 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -14,6 +14,7 @@ import { CreateDatasourceResponse, Datasource, DatasourcePlus, + ExternalTable, FetchDatasourceInfoRequest, FetchDatasourceInfoResponse, IntegrationBase, @@ -74,9 +75,12 @@ async function getAndMergeDatasource(datasource: Datasource) { async function buildSchemaHelper( datasource: Datasource -): Promise> { +): Promise> { const connector = (await getConnector(datasource)) as DatasourcePlus - return await connector.buildSchema(datasource._id!, datasource.entities!) + return await connector.buildSchema( + datasource._id!, + datasource.entities! as Record + ) } async function buildFilteredSchema( diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index c744a8f207..b895f68e78 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -14,7 +14,6 @@ import { SortJson, ExternalTable, TableRequest, - Table, } from "@budibase/types" import { OAuth2Client } from "google-auth-library" import { buildExternalTableId, finaliseExternalTables } from "./utils" @@ -279,8 +278,8 @@ class GoogleSheetsIntegration implements DatasourcePlus { async buildSchema( datasourceId: string, - entities: Record - ): Promise> { + entities: Record + ): Promise> { // not fully configured yet if (!this.config.auth) { return {} diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 783096a7dd..c64d8a36fe 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -11,7 +11,6 @@ import { DatasourceFeature, ConnectionInfo, SourceName, - Table, } from "@budibase/types" import { getSqlQuery, @@ -381,8 +380,8 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { */ async buildSchema( datasourceId: string, - entities: Record - ): Promise> { + entities: Record + ): Promise> { await this.connect() let tableInfo: MSSQLTablesResponse[] = await this.runSQL(this.TABLES_SQL) if (tableInfo == null || !Array.isArray(tableInfo)) { @@ -395,7 +394,7 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { .map((record: any) => record.TABLE_NAME) .filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1) - const tables: Record = {} + const tables: Record = {} for (let tableName of tableNames) { // get the column definition (type) const definition = await this.runSQL( diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index 90d0cd256c..1e5d3f54c3 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -10,7 +10,6 @@ import { DatasourceFeature, ConnectionInfo, SourceName, - Table, } from "@budibase/types" import { getSqlQuery, @@ -279,9 +278,9 @@ class MySQLIntegration extends Sql implements DatasourcePlus { async buildSchema( datasourceId: string, - entities: Record - ): Promise> { - const tables: { [key: string]: Table } = {} + entities: Record + ): Promise> { + const tables: { [key: string]: ExternalTable } = {} await this.connect() try { diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index fc4cd45cf6..6c1271bf0e 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -9,7 +9,6 @@ import { DatasourcePlus, DatasourceFeature, ConnectionInfo, - Table, } from "@budibase/types" import { buildExternalTableId, @@ -265,8 +264,8 @@ class OracleIntegration extends Sql implements DatasourcePlus { */ async buildSchema( datasourceId: string, - entities: Record - ): Promise> { + entities: Record + ): Promise> { const columnsResponse = await this.internalQuery({ sql: this.COLUMNS_SQL, }) diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 76487f7b65..3340b666e3 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -10,7 +10,6 @@ import { DatasourceFeature, ConnectionInfo, SourceName, - Table, } from "@budibase/types" import { getSqlQuery, @@ -272,8 +271,8 @@ class PostgresIntegration extends Sql implements DatasourcePlus { */ async buildSchema( datasourceId: string, - entities: Record - ): Promise> { + entities: Record + ): Promise> { let tableKeys: { [key: string]: string[] } = {} await this.openConnection() try { diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 6525bd07e2..2f594a7e87 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -297,9 +297,9 @@ function copyExistingPropsOver( * @param entities The old list of tables, if there was any to look for definitions in. */ export function finaliseExternalTables( - tables: Record, - entities: Record -): Record { + tables: Record, + entities: Record +): Record { let finalTables: Record = {} const tableIds = Object.values(tables).map(table => table._id!) for (let [name, table] of Object.entries(tables)) { diff --git a/packages/types/src/sdk/datasources.ts b/packages/types/src/sdk/datasources.ts index 2896bc62f5..a8ffd74b7a 100644 --- a/packages/types/src/sdk/datasources.ts +++ b/packages/types/src/sdk/datasources.ts @@ -1,4 +1,4 @@ -import { Table } from "../documents" +import { ExternalTable, Table } from "../documents" export const PASSWORD_REPLACEMENT = "--secret-value--" @@ -181,7 +181,7 @@ export interface DatasourcePlus extends IntegrationBase { getStringConcat(parts: string[]): string buildSchema( datasourceId: string, - entities: Record - ): Promise> + entities: Record + ): Promise> getTableNames(): Promise }