mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
1.27k stars 282 forks source link

function: support calling other datasources #887

Closed Janpot closed 1 year ago

Janpot commented 2 years ago

Duplicates

Latest version

Summary 💡

It should be possible to fetch the data of another datasource from the function datasource. This would allow composing different datasources together freely. Some ideas for a possible API:

export default async function ({ fetchDatasource }) {
  const {data} = await fetchDatasource('myPostgresDatasource', { params: { foo: 1 } }) 
}
import { fetchDatasource } from '@mui/toolpad-core'

export default async function ({}) {
  const {data} = await fetchDatasource('myPostgresDatasource', { params: { foo: 1 } }) 
}
import myPostgresDatasource from 'toolpad:myPostgresDatasource'

export default async function ({}) {
  const {data} = await myPostgresDatasource.fetch({ params: { foo: 1 } }) 
}

Examples 🌈

No response

Motivation 🔦

Bring the power of any datasource to the function datasource. e.g. db admin can write their postgres queries in a SQL editor, a toolpad developer can transform or compose those together in a function datasource.

apedroferreira commented 2 years ago

I like the first option better, as maybe we could add other useful things in the arguments in the future

prakhargupta1 commented 1 year ago

Closing it as it is already being done in custom functions.