Correct Way to Fetch Data from Multiple Schemas from Supabase? #5094
-
I'm trying to fetch data from different schemas using Supabase. By default, Refine only allows access to the public schema. However, I discovered that we can utilize multiple dataProviders, so I set up two: one for the public schema and another for the After doing this, I encountered a console warning: Can someone advise on the proper way to fetch data from multiple schemas in Supabase to avoid this warning? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hello @horizon-phoenix-fly, I think it's more of a supabase question, rather than refine. I think we don't limit you to access only public schema, you can pass your own client initiated with different schema to our data provider and it should work. And as you mentioned, you can use multiple data providers to access different schemas. I think this warning pops up because you have multiple supabase clients. |
Beta Was this translation helpful? Give feedback.
-
Hey @horizon-phoenix-fly, as an addition to the @BatuhanW's answer, I want to write a quick guide on how to achieve using multiple schemas in refine's supabase integration after swizzling the data provider. By using the After that we'll need to add a small feature that allows you to pick schemas instead of passing it once when creating the supabase client. You'll see that the data provider consists of couple of methods to achieve every crud operation. If this is not clear, I'm strongly advising you to check out the documents @BatuhanW shared above. Let me try to implement the multiple schema feature in the create: async ({ resource, variables, meta }) => {
- const query = supabaseClient.from(resource).insert(variables);
+ const query = supabaseClient.schema(meta?.schema ?? "public").from(resource).insert(variables);
if (meta?.select) {
query.select(meta.select);
}
const { data, error } = await query;
if (error) {
return handleError(error);
}
return {
data: (data || [])[0] as any,
};
}, Hope this helps 🙏 |
Beta Was this translation helpful? Give feedback.
Hey @horizon-phoenix-fly, as an addition to the @BatuhanW's answer, I want to write a quick guide on how to achieve using multiple schemas in refine's supabase integration after swizzling the data provider.
By using the
swizzle
command, you'll have the implementation of the@refinedev/supabase
'sdataProvider
andliveProvider
copied in your project. Hoping this is clear so far.After that we'll need to add a small feature that allows you to pick schemas instead of passing it once when creating the supabase client.
You'll see that the data provider consists of couple of methods to achieve every crud operation. If this is not clear, I'm strongly advising you to check out the documents @BatuhanW