Fix for issue with templated apps - some template apps are *very* old and therefore don't necessarily abide by the rules that are generally followed for new apps, this is something we should resolve, but for now adding an option that allows searching for only a specific document type.
This commit is contained in:
parent
0ea5235797
commit
cb99007a42
|
@ -1,6 +1,11 @@
|
|||
import { Knex, knex } from "knex"
|
||||
import * as dbCore from "../db"
|
||||
import { isIsoDateString, isValidFilter, getNativeSql } from "./utils"
|
||||
import {
|
||||
isIsoDateString,
|
||||
isValidFilter,
|
||||
getNativeSql,
|
||||
isExternalTable,
|
||||
} from "./utils"
|
||||
import { SqlStatements } from "./sqlStatements"
|
||||
import SqlTableQueryBuilder from "./sqlTable"
|
||||
import {
|
||||
|
@ -21,6 +26,7 @@ import {
|
|||
SqlClient,
|
||||
QueryOptions,
|
||||
JsonTypes,
|
||||
prefixed,
|
||||
} from "@budibase/types"
|
||||
import environment from "../environment"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
|
@ -556,8 +562,15 @@ class InternalBuilder {
|
|||
}
|
||||
|
||||
read(knex: Knex, json: QueryJson, limit: number): Knex.QueryBuilder {
|
||||
let { endpoint, resource, filters, paginate, relationships, tableAliases } =
|
||||
json
|
||||
let {
|
||||
endpoint,
|
||||
resource,
|
||||
filters,
|
||||
paginate,
|
||||
relationships,
|
||||
tableAliases,
|
||||
meta,
|
||||
} = json
|
||||
|
||||
const tableName = endpoint.entityId
|
||||
// select all if not specified
|
||||
|
@ -592,6 +605,12 @@ class InternalBuilder {
|
|||
query = this.addFilters(query, filters, json.meta.table, {
|
||||
aliases: tableAliases,
|
||||
})
|
||||
|
||||
// when searching internal tables make sure long looking for rows
|
||||
if (meta.documentType && !isExternalTable(meta.table)) {
|
||||
query.andWhereLike("_id", `${prefixed(meta.documentType)}%`)
|
||||
}
|
||||
|
||||
// add sorting to pre-query
|
||||
query = this.addSorting(query, json)
|
||||
const alias = tableAliases?.[tableName] || tableName
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
DocumentType,
|
||||
FieldType,
|
||||
Operation,
|
||||
QueryJson,
|
||||
|
@ -153,6 +154,7 @@ export async function search(
|
|||
meta: {
|
||||
table,
|
||||
tables: allTablesMap,
|
||||
documentType: DocumentType.ROW,
|
||||
},
|
||||
resource: {
|
||||
fields: buildInternalFieldList(table, allTables),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Operation, SortDirection } from "./datasources"
|
||||
import { Row, Table } from "../documents"
|
||||
import { Row, Table, DocumentType } from "../documents"
|
||||
import { SortType } from "../api"
|
||||
import { Knex } from "knex"
|
||||
|
||||
|
@ -117,6 +117,7 @@ export interface QueryJson {
|
|||
table: Table
|
||||
tables?: Record<string, Table>
|
||||
renamed?: RenameColumn
|
||||
documentType?: DocumentType
|
||||
}
|
||||
extra?: {
|
||||
idFilter?: SearchFilters
|
||||
|
|
Loading…
Reference in New Issue