DatasourcePlus deals exclusively in ExternalTables, reflect that in the types.

This commit is contained in:
Sam Rose 2023-10-12 16:38:15 +01:00
parent 85b3af2971
commit 1faf920c67
8 changed files with 24 additions and 25 deletions

View File

@ -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<Record<string, Table>> {
): Promise<Record<string, ExternalTable>> {
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<string, ExternalTable>
)
}
async function buildFilteredSchema(

View File

@ -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<string, Table>
): Promise<Record<string, Table>> {
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>> {
// not fully configured yet
if (!this.config.auth) {
return {}

View File

@ -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<string, Table>
): Promise<Record<string, Table>> {
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>> {
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<string, Table> = {}
const tables: Record<string, ExternalTable> = {}
for (let tableName of tableNames) {
// get the column definition (type)
const definition = await this.runSQL(

View File

@ -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<string, Table>
): Promise<Record<string, Table>> {
const tables: { [key: string]: Table } = {}
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>> {
const tables: { [key: string]: ExternalTable } = {}
await this.connect()
try {

View File

@ -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<string, Table>
): Promise<Record<string, Table>> {
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>> {
const columnsResponse = await this.internalQuery<OracleColumnsResponse>({
sql: this.COLUMNS_SQL,
})

View File

@ -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<string, Table>
): Promise<Record<string, Table>> {
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>> {
let tableKeys: { [key: string]: string[] } = {}
await this.openConnection()
try {

View File

@ -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<string, Table>,
entities: Record<string, Table>
): Record<string, Table> {
tables: Record<string, ExternalTable>,
entities: Record<string, ExternalTable>
): Record<string, ExternalTable> {
let finalTables: Record<string, Table> = {}
const tableIds = Object.values(tables).map(table => table._id!)
for (let [name, table] of Object.entries(tables)) {

View File

@ -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<string, Table>
): Promise<Record<string, Table>>
entities: Record<string, ExternalTable>
): Promise<Record<string, ExternalTable>>
getTableNames(): Promise<string[]>
}