Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.1 KiB

import TableFetch from "./TableFetch.js"
import { executeQuery, fetchQueryDefinition } from "api"
import { cloneDeep } from "lodash/fp.js"
export default class ViewFetch extends TableFetch {
SupportsSearch = false
SupportsSort = false
SupportsPagination = false
/**
* Fetches the schema for a view
* @param datasource the view datasource config
* @return {object} the view schema
*/
static async getSchema(datasource) {
if (!datasource?._id) {
return null
}
const definition = await fetchQueryDefinition(datasource._id)
return this.enrichSchema(definition?.schema)
}
/**
* Fetches a single page of data from the remote resource
*/
async getData() {
const { datasource } = this.options
// Set the default query params
let parameters = cloneDeep(datasource?.queryParams || {})
for (let param of datasource?.parameters || {}) {
if (!parameters[param.name]) {
parameters[param.name] = param.default
}
}
const res = await executeQuery({ queryId: datasource?._id, parameters })
return {
rows: res || [],
}
}
}