ra-data-postgrest
ra-data-postgrest copied to clipboard
use schema other than public?
Is there any way to use a different schema from public?
I didn't see an obvious way to do this; not sure if the limitation is in this package or supabase.
In supabase you can expose multiple schemas. Under the hood supabase is using Postgrest for exposing its api, and Postgrest allows targeting other/multiple schemas using the Accept-Profile
and Content-Profile
headers.
These 2 headers are not implemented by ra-data-postgrest yet.
I would propose to implement this using React-admin's meta
-parameter, in a way that a dataProvider request would look like this.
const { data, isLoading, error } = useGetOne(
'books',
{
id: 1,
meta: { schema: 'data' }
},
);
When ra-data-postgrest would find a schema in meta, it would then add the appropriate header (depending on the http method) to make Postgrest query the table/view/function from that schema.
Thoughts?
Thank you!!!
I'm not that familiar with postgrest or react-admin internals, so am probably the wrong person to give feedback.
My generic perspective is that the separation between 'books' and meta.schema.data is strange, and I would expect either a 1. factory method since postgrest apparently exposes only one schema at a time, or 2. simpler notation like 'data.books', since that's where the table is always going to be.
Or what about something like this?
const dataProvider = postgrestRestProvider('....', switchSchema('data'));
or object style
const dataProvider = postgrestRestProvider({ url, schema });
Hey @braco, we are currently working on several improvements and subsequently will add new features. Thus, we currently have kind of a feature-freeze. As of now, I like your suggestion of adding the schema as a parameter.
@braco , I just released v2.0.0-aplha.2 which includes custom schema functionality. Feel free to test it and whether you encounter any issues, I would be glad to hear of it ;) In that case, feel free to reopen this issue or create a new one.