Skip to content

Commit

Permalink
First test passes!
Browse files Browse the repository at this point in the history
  • Loading branch information
samwho committed Oct 19, 2023
1 parent 6517150 commit 7772973
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/sdk/app/rows/external.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
8 changes: 6 additions & 2 deletions packages/server/src/sdk/app/rows/search.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<Row[]> {
return pickApi(tableId).fetch(tableId)
}

export async function fetchRaw(tableId: string): Promise<Row[]> {
return pickApi(tableId).fetchRaw(tableId)
}

export async function fetchView(
tableId: string,
viewName: string,
Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/sdk/app/rows/search/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export async function fetch(tableId: string): Promise<Row[]> {
})
}

export async function fetchRaw(tableId: string): Promise<Row[]> {
return await handleRequest<Operation.READ>(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
Expand Down
9 changes: 4 additions & 5 deletions packages/server/src/sdk/app/rows/search/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,13 @@ export async function exportRows(
}

export async function fetch(tableId: string): Promise<Row[]> {
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<Row[]> {
const db = context.getAppDB()
let rows
if (tableId === InternalTables.USER_METADATA) {
rows = await sdk.users.fetchMetadata()
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/sdk/app/tables/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7772973

Please sign in to comment.