1
0
Fork 0
mirror of synced 2024-09-18 02:08:34 +12:00
budibase/packages/client/src/utils/fetch/TableFetch.js

36 lines
866 B
JavaScript
Raw Normal View History

import { get } from "svelte/store"
import DataFetch from "./DataFetch.js"
import { searchTable } from "api"
export default class TableFetch extends DataFetch {
determineFeatureFlags() {
this.supportsSearch = true
this.supportsSort = true
this.supportsPagination = true
}
async getData() {
const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
this.options
const { tableId } = datasource
const { cursor, query } = get(this.store)
// Search table
const res = await searchTable({
tableId,
query,
limit,
sort: sortColumn,
sortOrder: sortOrder?.toLowerCase() ?? "ascending",
sortType,
paginate,
bookmark: cursor,
})
return {
rows: res?.rows || [],
hasNextPage: res?.hasNextPage || false,
cursor: res?.bookmark || null,
}
}
}