budibase/packages/frontend-core/src/fetch/ViewV2Fetch.js

33 lines
787 B
JavaScript
Raw Normal View History

2023-07-19 10:16:12 +02:00
import DataFetch from "./DataFetch.js"
export default class ViewV2Fetch extends DataFetch {
async getSchema(datasource, definition) {
return definition.schema
}
async getDefinition(datasource) {
try {
2023-07-21 13:25:13 +02:00
const table = await this.API.fetchTableDefinition(datasource.tableId)
2023-07-21 13:28:19 +02:00
const view = Object.values(table.views).find(v => v.id === datasource.id)
2023-07-21 13:25:13 +02:00
const { schema } = view
2023-07-20 09:46:27 +02:00
return { schema }
2023-07-19 10:16:12 +02:00
} catch (error) {
this.store.update(state => ({
...state,
error,
}))
return null
}
}
async getData() {
const { datasource } = this.options
try {
2023-07-21 09:58:58 +02:00
const res = await this.API.viewV2.fetch(datasource.id)
2023-07-19 10:16:12 +02:00
return { rows: res?.rows || [] }
} catch (error) {
return { rows: [] }
}
}
}