2020-11-12 13:24:45 +01:00
|
|
|
import { fetchTableData } from "./tables"
|
2020-11-12 10:07:09 +01:00
|
|
|
import { fetchViewData } from "./views"
|
|
|
|
import { fetchRelationshipData } from "./relationships"
|
2020-11-12 13:24:45 +01:00
|
|
|
import { enrichRows } from "./rows"
|
2020-11-12 10:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all rows for a particular Budibase data source.
|
|
|
|
*/
|
|
|
|
export const fetchDatasource = async datasource => {
|
2020-11-12 13:24:45 +01:00
|
|
|
if (!datasource || !datasource.type) {
|
2020-11-12 10:07:09 +01:00
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch all rows in data source
|
2020-11-12 13:24:45 +01:00
|
|
|
const { type, tableId } = datasource
|
2020-11-12 10:07:09 +01:00
|
|
|
let rows = []
|
|
|
|
if (type === "table") {
|
2020-11-12 13:24:45 +01:00
|
|
|
rows = await fetchTableData(tableId)
|
2020-11-12 10:07:09 +01:00
|
|
|
} else if (type === "view") {
|
|
|
|
rows = await fetchViewData(datasource)
|
|
|
|
} else if (type === "link") {
|
|
|
|
rows = await fetchRelationshipData(tableId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enrich rows
|
2020-11-12 13:24:45 +01:00
|
|
|
return await enrichRows(rows, tableId)
|
2020-11-12 10:07:09 +01:00
|
|
|
}
|