Merge branch 'fix/sql-param-limits' of github.com:Budibase/budibase into fix/sql-param-limits
This commit is contained in:
commit
05fd9e8b81
|
@ -551,11 +551,16 @@ export class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
const hasFilters = dataFilters.hasFilters(query.filters)
|
const hasFilters = dataFilters.hasFilters(query.filters)
|
||||||
const limit = query.paginate?.limit || 100
|
const limit = query.paginate?.limit || 100
|
||||||
const page: number =
|
let offset = query.paginate?.offset || 0
|
||||||
typeof query.paginate?.page === "number"
|
|
||||||
? query.paginate.page
|
let page = query.paginate?.page
|
||||||
: parseInt(query.paginate?.page || "1")
|
if (typeof page === "string") {
|
||||||
const offset = (page - 1) * limit
|
page = parseInt(page)
|
||||||
|
}
|
||||||
|
if (page !== undefined) {
|
||||||
|
offset = page * limit
|
||||||
|
}
|
||||||
|
|
||||||
const sheet = this.client.sheetsByTitle[query.sheet]
|
const sheet = this.client.sheetsByTitle[query.sheet]
|
||||||
let rows: GoogleSpreadsheetRow[] = []
|
let rows: GoogleSpreadsheetRow[] = []
|
||||||
if (query.paginate && !hasFilters) {
|
if (query.paginate && !hasFilters) {
|
||||||
|
|
|
@ -208,6 +208,42 @@ describe("Google Sheets Integration", () => {
|
||||||
expect(row2.name).toEqual("Test Contact 2")
|
expect(row2.name).toEqual("Test Contact 2")
|
||||||
expect(row2.description).toEqual("original description 2")
|
expect(row2.description).toEqual("original description 2")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can paginate correctly", async () => {
|
||||||
|
await config.api.row.bulkImport(table._id!, {
|
||||||
|
rows: Array.from({ length: 248 }, (_, i) => ({
|
||||||
|
name: `${i}`,
|
||||||
|
description: "",
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
let resp = await config.api.row.search(table._id!, {
|
||||||
|
tableId: table._id!,
|
||||||
|
query: {},
|
||||||
|
paginate: true,
|
||||||
|
limit: 10,
|
||||||
|
})
|
||||||
|
let rows = resp.rows
|
||||||
|
|
||||||
|
while (resp.hasNextPage) {
|
||||||
|
resp = await config.api.row.search(table._id!, {
|
||||||
|
tableId: table._id!,
|
||||||
|
query: {},
|
||||||
|
paginate: true,
|
||||||
|
limit: 10,
|
||||||
|
bookmark: resp.bookmark,
|
||||||
|
})
|
||||||
|
rows = rows.concat(resp.rows)
|
||||||
|
if (rows.length > 250) {
|
||||||
|
throw new Error("Too many rows returned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(rows.length).toEqual(250)
|
||||||
|
expect(rows.map(row => row.name)).toEqual(
|
||||||
|
expect.arrayContaining(Array.from({ length: 248 }, (_, i) => `${i}`))
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
|
|
Loading…
Reference in New Issue