Ensure fetching datasources always returns an array result
This commit is contained in:
parent
8789d576af
commit
7c0a2bc2f5
|
@ -3,7 +3,6 @@ import { fetchTableData } from "./tables"
|
||||||
import { fetchViewData } from "./views"
|
import { fetchViewData } from "./views"
|
||||||
import { fetchRelationshipData } from "./relationships"
|
import { fetchRelationshipData } from "./relationships"
|
||||||
import { executeQuery } from "./queries"
|
import { executeQuery } from "./queries"
|
||||||
import { enrichRows } from "./rows"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all rows for a particular Budibase data source.
|
* Fetches all rows for a particular Budibase data source.
|
||||||
|
@ -28,7 +27,7 @@ export const fetchDatasource = async datasource => {
|
||||||
parameters[param.name] = param.default
|
parameters[param.name] = param.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await executeQuery({ queryId: datasource._id, parameters })
|
rows = await executeQuery({ queryId: datasource._id, parameters })
|
||||||
} else if (type === "link") {
|
} else if (type === "link") {
|
||||||
rows = await fetchRelationshipData({
|
rows = await fetchRelationshipData({
|
||||||
rowId: datasource.rowId,
|
rowId: datasource.rowId,
|
||||||
|
@ -37,6 +36,6 @@ export const fetchDatasource = async datasource => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enrich rows so they can displayed properly
|
// Enrich the result is always an array
|
||||||
return await enrichRows(rows, tableId)
|
return Array.isArray(rows) ? rows : []
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,10 @@ export const deleteRows = async ({ tableId, rows }) => {
|
||||||
* be properly displayed.
|
* be properly displayed.
|
||||||
*/
|
*/
|
||||||
export const enrichRows = async (rows, tableId) => {
|
export const enrichRows = async (rows, tableId) => {
|
||||||
if (rows && rows.length && tableId) {
|
if (!Array.isArray(rows)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
if (rows.length && tableId) {
|
||||||
// Fetch table schema so we can check column types
|
// Fetch table schema so we can check column types
|
||||||
const tableDefinition = await fetchTableDefinition(tableId)
|
const tableDefinition = await fetchTableDefinition(tableId)
|
||||||
const schema = tableDefinition && tableDefinition.schema
|
const schema = tableDefinition && tableDefinition.schema
|
||||||
|
|
Loading…
Reference in New Issue