diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index cff594d329..a05c640c33 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -72,7 +72,7 @@ export async function fetchView(ctx: any) { export async function fetch(ctx: any) { const tableId = utils.getTableId(ctx) - ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId, ctx), { + ctx.body = await quotas.addQuery(() => sdk.rows.fetch(tableId), { datasourceId: tableId, }) } diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index c37494192b..56dea32025 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -29,8 +29,8 @@ export async function exportRows(tableId: string, ctx: Ctx) { return pickApi(tableId).exportRows(ctx) } -export async function fetch(tableId: string, ctx: Ctx) { - return pickApi(tableId).fetch(ctx) +export async function fetch(tableId: string) { + return pickApi(tableId).fetch(tableId) } export async function fetchView(tableId: string, ctx: Ctx) { diff --git a/packages/server/src/sdk/app/rows/search/external.ts b/packages/server/src/sdk/app/rows/search/external.ts index c48f984a2d..abed06eb31 100644 --- a/packages/server/src/sdk/app/rows/search/external.ts +++ b/packages/server/src/sdk/app/rows/search/external.ts @@ -161,8 +161,7 @@ export async function exportRows(ctx: Ctx) { return apiFileReturn(content) } -export async function fetch(ctx: Ctx) { - const tableId = ctx.params.tableId +export async function fetch(tableId: string) { return handleRequest(Operation.READ, tableId, { includeSqlRelationships: IncludeRelationship.INCLUDE, }) @@ -172,6 +171,6 @@ export async function fetchView(ctx: Ctx) { // there are no views in external datasources, shouldn't ever be called // for now just fetch const split = ctx.params.viewName.split("all_") - ctx.params.tableId = split[1] ? split[1] : split[0] - return fetch(ctx) + const tableId = split[1] ? split[1] : split[0] + return fetch(tableId) } diff --git a/packages/server/src/sdk/app/rows/search/internal.ts b/packages/server/src/sdk/app/rows/search/internal.ts index 6545761283..d3d15deb53 100644 --- a/packages/server/src/sdk/app/rows/search/internal.ts +++ b/packages/server/src/sdk/app/rows/search/internal.ts @@ -27,12 +27,13 @@ import { import sdk from "../../../../sdk" export async function search(ctx: Ctx) { + const { tableId } = ctx.params + // Fetch the whole table when running in cypress, as search doesn't work if (!env.COUCH_DB_URL && env.isCypress()) { - return { rows: await fetch(ctx) } + return { rows: await fetch(tableId) } } - const { tableId } = ctx.params const db = context.getAppDB() const { paginate, query, ...params } = ctx.request.body params.version = ctx.version @@ -121,13 +122,13 @@ export async function exportRows(ctx: Ctx) { } } -export async function fetch(ctx: Ctx) { +export async function fetch(tableId: string) { const db = context.getAppDB() - const tableId = ctx.params.tableId let table = await db.get(tableId) let rows = await getRawTableData(db, tableId) - return outputProcessing(table, rows) + const result = await outputProcessing(table, rows) + return result } async function getRawTableData(db: Database, tableId: string) { @@ -151,7 +152,7 @@ export async function fetchView(ctx: Ctx) { // if this is a table view being looked for just transfer to that if (viewName.startsWith(DocumentType.TABLE)) { ctx.params.tableId = viewName - return fetch(ctx) + return fetch(viewName) } const db = context.getAppDB()