From 77729737bce3cceabcef7290bbf46321939bccd4 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 19 Oct 2023 09:47:50 +0100 Subject: [PATCH] First test passes! --- packages/server/src/sdk/app/rows/external.ts | 2 +- packages/server/src/sdk/app/rows/search.ts | 8 ++++++-- packages/server/src/sdk/app/rows/search/external.ts | 6 ++++++ packages/server/src/sdk/app/rows/search/internal.ts | 9 ++++----- packages/server/src/sdk/app/tables/migration.ts | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/server/src/sdk/app/rows/external.ts b/packages/server/src/sdk/app/rows/external.ts index 8bcf89a3f5..beae02e134 100644 --- a/packages/server/src/sdk/app/rows/external.ts +++ b/packages/server/src/sdk/app/rows/external.ts @@ -1,4 +1,4 @@ -import { IncludeRelationship, Operation, Row } from "@budibase/types" +import { IncludeRelationship, Operation } from "@budibase/types" import { handleRequest } from "../../../api/controllers/row/external" import { breakRowIdField } from "../../../integrations/utils" diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index f75bd07437..221aa6486c 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -1,4 +1,4 @@ -import { SearchFilters, SearchParams } from "@budibase/types" +import { Row, SearchFilters, SearchParams } from "@budibase/types" import { isExternalTable } from "../../../integrations/utils" import * as internal from "./search/internal" import * as external from "./search/external" @@ -45,10 +45,14 @@ export async function exportRows( return pickApi(options.tableId).exportRows(options) } -export async function fetch(tableId: string) { +export async function fetch(tableId: string): Promise { return pickApi(tableId).fetch(tableId) } +export async function fetchRaw(tableId: string): Promise { + return pickApi(tableId).fetchRaw(tableId) +} + export async function fetchView( tableId: string, viewName: string, diff --git a/packages/server/src/sdk/app/rows/search/external.ts b/packages/server/src/sdk/app/rows/search/external.ts index c41efad171..981ae1bf8d 100644 --- a/packages/server/src/sdk/app/rows/search/external.ts +++ b/packages/server/src/sdk/app/rows/search/external.ts @@ -186,6 +186,12 @@ export async function fetch(tableId: string): Promise { }) } +export async function fetchRaw(tableId: string): Promise { + return await handleRequest(Operation.READ, tableId, { + includeSqlRelationships: IncludeRelationship.INCLUDE, + }) +} + export async function fetchView(viewName: string) { // there are no views in external datasources, shouldn't ever be called // for now just fetch diff --git a/packages/server/src/sdk/app/rows/search/internal.ts b/packages/server/src/sdk/app/rows/search/internal.ts index 779ff5f777..58611c8849 100644 --- a/packages/server/src/sdk/app/rows/search/internal.ts +++ b/packages/server/src/sdk/app/rows/search/internal.ts @@ -140,14 +140,13 @@ export async function exportRows( } export async function fetch(tableId: string): Promise { - const db = context.getAppDB() - const table = await sdk.tables.getTable(tableId) - const rows = await getRawTableData(db, tableId) + const rows = await fetchRaw(tableId) return await outputProcessing(table, rows) } -async function getRawTableData(db: Database, tableId: string) { +export async function fetchRaw(tableId: string): Promise { + const db = context.getAppDB() let rows if (tableId === InternalTables.USER_METADATA) { rows = await sdk.users.fetchMetadata() @@ -182,7 +181,7 @@ export async function fetchView( }) } else { const tableId = viewInfo.meta.tableId - const data = await getRawTableData(db, tableId) + const data = await fetchRaw(tableId) response = await inMemoryViews.runView( viewInfo, calculation as string, diff --git a/packages/server/src/sdk/app/tables/migration.ts b/packages/server/src/sdk/app/tables/migration.ts index a08b56826d..cea15114a1 100644 --- a/packages/server/src/sdk/app/tables/migration.ts +++ b/packages/server/src/sdk/app/tables/migration.ts @@ -28,7 +28,7 @@ export async function migrate( await migrator.doMigration() delete table.schema[oldColumn.name] - await sdk.tables.saveTable(table) + table = await sdk.tables.saveTable(table) await updateLinks({ eventType: EventType.TABLE_UPDATED, table, oldTable }) } @@ -88,7 +88,7 @@ class UserColumnMigrator implements ColumnMigrator { ) {} async doMigration() { - let rows = await sdk.rows.fetch(this.table._id!) + let rows = await sdk.rows.fetchRaw(this.table._id!) let rowsById = rows.reduce((acc, row) => { acc[row._id!] = row return acc