Merge branch 'master' into chore/search-tests-from-views
This commit is contained in:
commit
576ebc997e
|
@ -1,5 +1,5 @@
|
|||
export * as utils from "./utils"
|
||||
|
||||
export { default as Sql } from "./sql"
|
||||
export { default as Sql, COUNT_FIELD_NAME } from "./sql"
|
||||
export { default as SqlTable } from "./sqlTable"
|
||||
export * as designDoc from "./designDoc"
|
||||
|
|
|
@ -43,6 +43,8 @@ import { cloneDeep } from "lodash"
|
|||
|
||||
type QueryFunction = (query: SqlQuery | SqlQuery[], operation: Operation) => any
|
||||
|
||||
export const COUNT_FIELD_NAME = "__bb_total"
|
||||
|
||||
function getBaseLimit() {
|
||||
const envLimit = environment.SQL_MAX_ROWS
|
||||
? parseInt(environment.SQL_MAX_ROWS)
|
||||
|
@ -846,7 +848,7 @@ class InternalBuilder {
|
|||
throw new Error("SQL counting requires primary key to be supplied")
|
||||
}
|
||||
return query.countDistinct(
|
||||
`${this.getTableName()}.${this.table.primary[0]} as __bb_total`
|
||||
`${this.getTableName()}.${this.table.primary[0]} as ${COUNT_FIELD_NAME}`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
// Look up the component tree and find something that is provided by an
|
||||
// ancestor that matches our datasource. This is for backwards compatibility
|
||||
// as previously we could use the "closest" context.
|
||||
for (let id of path.reverse().slice(1)) {
|
||||
for (let id of path.toReversed().slice(1)) {
|
||||
// Check for matching view datasource
|
||||
if (
|
||||
dataSource.type === "viewV2" &&
|
||||
|
|
|
@ -20,7 +20,7 @@ import { Format } from "../../../api/controllers/view/exporters"
|
|||
import sdk from "../.."
|
||||
import { extractViewInfoFromID, isRelationshipColumn } from "../../../db/utils"
|
||||
import { isSQL } from "../../../integrations/utils"
|
||||
import { docIds } from "@budibase/backend-core"
|
||||
import { docIds, sql } from "@budibase/backend-core"
|
||||
import { getTableFromSource } from "../../../api/controllers/row/utils"
|
||||
|
||||
const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
|
||||
|
@ -57,8 +57,12 @@ export function getSQLClient(datasource: Datasource): SqlClient {
|
|||
export function processRowCountResponse(
|
||||
response: DatasourcePlusQueryResponse
|
||||
): number {
|
||||
if (response && response.length === 1 && "__bb_total" in response[0]) {
|
||||
const total = response[0].__bb_total
|
||||
if (
|
||||
response &&
|
||||
response.length === 1 &&
|
||||
sql.COUNT_FIELD_NAME in response[0]
|
||||
) {
|
||||
const total = response[0][sql.COUNT_FIELD_NAME]
|
||||
return typeof total === "number" ? total : parseInt(total)
|
||||
} else {
|
||||
throw new Error("Unable to count rows in query - no count response")
|
||||
|
|
Loading…
Reference in New Issue