Don't export couchdb fields
This commit is contained in:
parent
62fa05a855
commit
fe2b2bb097
|
@ -11,6 +11,7 @@ import {
|
||||||
SearchResponse,
|
SearchResponse,
|
||||||
SortType,
|
SortType,
|
||||||
Table,
|
Table,
|
||||||
|
TableSchema,
|
||||||
User,
|
User,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { getGlobalUsersFromMetadata } from "../../../../utilities/global"
|
import { getGlobalUsersFromMetadata } from "../../../../utilities/global"
|
||||||
|
@ -137,6 +138,9 @@ export async function exportRows(
|
||||||
let rows: Row[] = []
|
let rows: Row[] = []
|
||||||
let schema = table.schema
|
let schema = table.schema
|
||||||
let headers
|
let headers
|
||||||
|
|
||||||
|
result = trimFields(result, schema)
|
||||||
|
|
||||||
// Filter data to only specified columns if required
|
// Filter data to only specified columns if required
|
||||||
if (columns && columns.length) {
|
if (columns && columns.length) {
|
||||||
for (let i = 0; i < result.length; i++) {
|
for (let i = 0; i < result.length; i++) {
|
||||||
|
@ -299,3 +303,13 @@ async function getView(db: Database, viewName: string) {
|
||||||
}
|
}
|
||||||
return viewInfo
|
return viewInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trimFields(rows: Row[], schema: TableSchema) {
|
||||||
|
const allowedFields = ["_id", ...Object.keys(schema)]
|
||||||
|
const result = rows.map(row =>
|
||||||
|
Object.keys(row)
|
||||||
|
.filter(key => allowedFields.includes(key))
|
||||||
|
.reduce((acc, key) => ({ ...acc, [key]: row[key] }), {} as Row)
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue