1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00
budibase/packages/client/src/api/datasources.js

32 lines
843 B
JavaScript
Raw Normal View History

import { fetchTableData } from "./tables"
import { fetchViewData } from "./views"
import { fetchRelationshipData } from "./relationships"
import { enrichRows } from "./rows"
/**
* Fetches all rows for a particular Budibase data source.
*/
export const fetchDatasource = async (datasource, dataContext) => {
if (!datasource || !datasource.type) {
return []
}
// Fetch all rows in data source
const { type, tableId, fieldName } = datasource
let rows = []
if (type === "table") {
rows = await fetchTableData(tableId)
} else if (type === "view") {
rows = await fetchViewData(datasource)
} else if (type === "link") {
rows = await fetchRelationshipData({
2020-11-25 00:28:31 +13:00
rowId: dataContext?._id,
tableId: dataContext?.tableId,
fieldName,
})
}
// Enrich rows
return await enrichRows(rows, tableId)
}