This commit is contained in:
mike12345567 2021-07-01 14:25:23 +01:00
parent a13b5111bb
commit e82e175b9c
3 changed files with 14 additions and 23 deletions

View File

@ -1,5 +1,9 @@
const { makeExternalQuery } = require("./utils") const { makeExternalQuery } = require("./utils")
const { DataSourceOperation, SortDirection, FieldTypes } = require("../../../constants") const {
DataSourceOperation,
SortDirection,
FieldTypes,
} = require("../../../constants")
const { getAllExternalTables } = require("../table/utils") const { getAllExternalTables } = require("../table/utils")
const { const {
breakExternalTableId, breakExternalTableId,
@ -81,12 +85,7 @@ async function handleRequest(
} }
await Promise.all(promises) await Promise.all(promises)
} }
const output = outputProcessing( const output = outputProcessing(response, table, relationships, tables)
response,
table,
relationships,
tables
)
// if reading it'll just be an array of rows, return whole thing // if reading it'll just be an array of rows, return whole thing
return operation === DataSourceOperation.READ && Array.isArray(response) return operation === DataSourceOperation.READ && Array.isArray(response)
? output ? output
@ -256,7 +255,11 @@ exports.fetchEnrichedRow = async ctx => {
// this seems like a lot of work, but basically we need to dig deeper for the enrich // this seems like a lot of work, but basically we need to dig deeper for the enrich
// for a single row, there is probably a better way to do this with some smart multi-layer joins // for a single row, there is probably a better way to do this with some smart multi-layer joins
for (let [fieldName, field] of Object.entries(table.schema)) { for (let [fieldName, field] of Object.entries(table.schema)) {
if (field.type !== FieldTypes.LINK || !row[fieldName] || row[fieldName].length === 0) { if (
field.type !== FieldTypes.LINK ||
!row[fieldName] ||
row[fieldName].length === 0
) {
continue continue
} }
const links = row[fieldName] const links = row[fieldName]
@ -275,7 +278,7 @@ exports.fetchEnrichedRow = async ctx => {
[linkedTable.primary]: linkedIds, [linkedTable.primary]: linkedIds,
}, },
}, },
}, }
) )
} }
return row return row

View File

@ -76,12 +76,7 @@ exports.generateIdForRow = (row, table) => {
return generateRowIdField(idParts) return generateRowIdField(idParts)
} }
exports.updateRelationshipColumns = ( exports.updateRelationshipColumns = (row, rows, relationships, allTables) => {
row,
rows,
relationships,
allTables
) => {
const columns = {} const columns = {}
for (let relationship of relationships) { for (let relationship of relationships) {
const linkedTable = allTables[relationship.tableName] const linkedTable = allTables[relationship.tableName]
@ -109,12 +104,7 @@ exports.updateRelationshipColumns = (
return rows return rows
} }
exports.outputProcessing = ( exports.outputProcessing = (rows, table, relationships, allTables) => {
rows,
table,
relationships,
allTables
) => {
// if no rows this is what is returned? Might be PG only // if no rows this is what is returned? Might be PG only
if (rows[0].read === true) { if (rows[0].read === true) {
return [] return []

View File

@ -1,5 +1,3 @@
import {breakExternalTableId} from "../../../integrations/utils"
const CouchDB = require("../../../db") const CouchDB = require("../../../db")
const csvParser = require("../../../utilities/csvParser") const csvParser = require("../../../utilities/csvParser")
const { const {