1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Merge pull request #14305 from Budibase/fix/export-row-correct-search

Fixing export rows to use correct search
This commit is contained in:
Michael Drury 2024-08-02 15:12:41 +01:00 committed by GitHub
commit f48a9bec5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 95 additions and 90 deletions

View file

@ -8,7 +8,6 @@ import {
import { isExternalTableID } from "../../../integrations/utils" import { isExternalTableID } from "../../../integrations/utils"
import * as internal from "./search/internal" import * as internal from "./search/internal"
import * as external from "./search/external" import * as external from "./search/external"
import * as sqs from "./search/sqs"
import { ExportRowsParams, ExportRowsResult } from "./search/types" import { ExportRowsParams, ExportRowsResult } from "./search/types"
import { dataFilters } from "@budibase/shared-core" import { dataFilters } from "@budibase/shared-core"
import sdk from "../../index" import sdk from "../../index"
@ -55,9 +54,9 @@ export async function search(
if (isExternalTable) { if (isExternalTable) {
return external.search(options, table) return external.search(options, table)
} else if (dbCore.isSqsEnabledForTenant()) { } else if (dbCore.isSqsEnabledForTenant()) {
return sqs.search(options, table) return internal.sqs.search(options, table)
} else { } else {
return internal.search(options, table) return internal.lucene.search(options, table)
} }
} }

View file

@ -0,0 +1,3 @@
export * as sqs from "./sqs"
export * as lucene from "./lucene"
export * from "./internal"

View file

@ -1,90 +1,30 @@
import { context, HTTPError } from "@budibase/backend-core" import { context, HTTPError } from "@budibase/backend-core"
import { PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" import env from "../../../../../environment"
import env from "../../../../environment" import { getRowParams, InternalTables } from "../../../../../db/utils"
import { fullSearch, paginatedSearch } from "./utils"
import { getRowParams, InternalTables } from "../../../../db/utils"
import { import {
Database, Database,
DocumentType, DocumentType,
Row, Row,
RowSearchParams,
SearchResponse,
SortType,
Table, Table,
TableSchema, TableSchema,
User,
} from "@budibase/types" } from "@budibase/types"
import { getGlobalUsersFromMetadata } from "../../../../utilities/global" import { outputProcessing } from "../../../../../utilities/rowProcessor"
import { outputProcessing } from "../../../../utilities/rowProcessor"
import { import {
csv, csv,
Format, Format,
json, json,
jsonWithSchema, jsonWithSchema,
} from "../../../../api/controllers/view/exporters" } from "../../../../../api/controllers/view/exporters"
import * as inMemoryViews from "../../../../db/inMemoryView" import * as inMemoryViews from "../../../../../db/inMemoryView"
import { import {
getFromDesignDoc, getFromDesignDoc,
getFromMemoryDoc, getFromMemoryDoc,
migrateToDesignView, migrateToDesignView,
migrateToInMemoryView, migrateToInMemoryView,
} from "../../../../api/controllers/view/utils" } from "../../../../../api/controllers/view/utils"
import sdk from "../../../../sdk" import sdk from "../../../../../sdk"
import { ExportRowsParams, ExportRowsResult } from "./types" import { ExportRowsParams, ExportRowsResult } from "../types"
import pick from "lodash/pick" import { breakRowIdField } from "../../../../../integrations/utils"
import { breakRowIdField } from "../../../../integrations/utils"
export async function search(
options: RowSearchParams,
table: Table
): Promise<SearchResponse<Row>> {
const { tableId } = options
const { paginate, query } = options
const params: RowSearchParams = {
tableId: options.tableId,
sort: options.sort,
sortOrder: options.sortOrder,
sortType: options.sortType,
limit: options.limit,
bookmark: options.bookmark,
version: options.version,
disableEscaping: options.disableEscaping,
query: {},
}
if (params.sort && !params.sortType) {
const schema = table.schema
const sortField = schema[params.sort]
params.sortType =
sortField.type === "number" ? SortType.NUMBER : SortType.STRING
}
let response
if (paginate) {
response = await paginatedSearch(query, params)
} else {
response = await fullSearch(query, params)
}
// Enrich search results with relationships
if (response.rows && response.rows.length) {
// enrich with global users if from users table
if (tableId === InternalTables.USER_METADATA) {
response.rows = await getGlobalUsersFromMetadata(response.rows as User[])
}
if (options.fields) {
const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS]
response.rows = response.rows.map((r: any) => pick(r, fields))
}
response.rows = await outputProcessing(table, response.rows)
}
return response
}
export async function exportRows( export async function exportRows(
options: ExportRowsParams options: ExportRowsParams
@ -123,15 +63,12 @@ export async function exportRows(
result = await outputProcessing<Row[]>(table, response) result = await outputProcessing<Row[]>(table, response)
} else if (query) { } else if (query) {
let searchResponse = await search( let searchResponse = await sdk.rows.search({
{ tableId,
tableId, query,
query, sort,
sort, sortOrder,
sortOrder, })
},
table
)
result = searchResponse.rows result = searchResponse.rows
} }

View file

@ -0,0 +1,66 @@
import { PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core"
import { fullSearch, paginatedSearch } from "../utils"
import { InternalTables } from "../../../../../db/utils"
import {
Row,
RowSearchParams,
SearchResponse,
SortType,
Table,
User,
} from "@budibase/types"
import { getGlobalUsersFromMetadata } from "../../../../../utilities/global"
import { outputProcessing } from "../../../../../utilities/rowProcessor"
import pick from "lodash/pick"
export async function search(
options: RowSearchParams,
table: Table
): Promise<SearchResponse<Row>> {
const { tableId } = options
const { paginate, query } = options
const params: RowSearchParams = {
tableId: options.tableId,
sort: options.sort,
sortOrder: options.sortOrder,
sortType: options.sortType,
limit: options.limit,
bookmark: options.bookmark,
version: options.version,
disableEscaping: options.disableEscaping,
query: {},
}
if (params.sort && !params.sortType) {
const schema = table.schema
const sortField = schema[params.sort]
params.sortType =
sortField.type === "number" ? SortType.NUMBER : SortType.STRING
}
let response
if (paginate) {
response = await paginatedSearch(query, params)
} else {
response = await fullSearch(query, params)
}
// Enrich search results with relationships
if (response.rows && response.rows.length) {
// enrich with global users if from users table
if (tableId === InternalTables.USER_METADATA) {
response.rows = await getGlobalUsersFromMetadata(response.rows as User[])
}
if (options.fields) {
const fields = [...options.fields, ...PROTECTED_INTERNAL_COLUMNS]
response.rows = response.rows.map((r: any) => pick(r, fields))
}
response.rows = await outputProcessing(table, response.rows)
}
return response
}

View file

@ -18,31 +18,31 @@ import {
import { import {
buildInternalRelationships, buildInternalRelationships,
sqlOutputProcessing, sqlOutputProcessing,
} from "../../../../api/controllers/row/utils" } from "../../../../../api/controllers/row/utils"
import { import {
decodeNonAscii, decodeNonAscii,
mapToUserColumn, mapToUserColumn,
USER_COLUMN_PREFIX, USER_COLUMN_PREFIX,
} from "../../tables/internal/sqs" } from "../../../tables/internal/sqs"
import sdk from "../../../index" import sdk from "../../../../index"
import { import {
context, context,
sql, sql,
SQLITE_DESIGN_DOC_ID, SQLITE_DESIGN_DOC_ID,
SQS_DATASOURCE_INTERNAL, SQS_DATASOURCE_INTERNAL,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { generateJunctionTableID } from "../../../../db/utils" import { generateJunctionTableID } from "../../../../../db/utils"
import AliasTables from "../sqlAlias" import AliasTables from "../../sqlAlias"
import { outputProcessing } from "../../../../utilities/rowProcessor" import { outputProcessing } from "../../../../../utilities/rowProcessor"
import pick from "lodash/pick" import pick from "lodash/pick"
import { processRowCountResponse } from "../utils" import { processRowCountResponse } from "../../utils"
import { import {
updateFilterKeys, updateFilterKeys,
getRelationshipColumns, getRelationshipColumns,
getTableIDList, getTableIDList,
} from "./filters" } from "../filters"
import { dataFilters, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" import { dataFilters, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core"
import { isSearchingByRowID } from "./utils" import { isSearchingByRowID } from "../utils"
import tracer from "dd-trace" import tracer from "dd-trace"
const builder = new sql.Sql(SqlClient.SQL_LITE) const builder = new sql.Sql(SqlClient.SQL_LITE)