correct-apricot
correct-apricot2mo ago

inference with Supabase

Hi, I'm trying to setup a basic crud with Supabase as data provider and antd for generating the UI's with the inferencer. Now the schema I have in postgresql, is not the public one. But with another name. I passed this name when configuring the Supabase client. But when I try to browse to the page in chrome it throws an error. In the console logs there is mentioned that the schema should be the public schema. Is there no way to configure the schema does it really have to be the public one?
5 Replies
kapa.ai
kapa.ai2mo ago
Hi @Busulle. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- It is possible to configure the schema in Supabase to use a custom schema instead of the default public schema. However, there are some steps and considerations to ensure it works correctly with refine. Steps to Configure Custom Schema in Supabase with refine 1. Configure Supabase Client with Custom Schema: You need to set up your supabaseClient with the custom schema. Here is an example of how to do it:
// src/utility/supabaseClient.ts
import { createClient } from "@refinedev/supabase";

const SUPABASE_URL = "your_supabase_url";
const SUPABASE_KEY = "your_supabase_key";

export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
db: {
schema: "custom", // Replace "custom" with your schema name
},
auth: {
persistSession: true,
},
});

// src/utility/supabaseClient.ts
import { createClient } from "@refinedev/supabase";

const SUPABASE_URL = "your_supabase_url";
const SUPABASE_KEY = "your_supabase_key";

export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
db: {
schema: "custom", // Replace "custom" with your schema name
},
auth: {
persistSession: true,
},
});

2. Pass Schema in Meta Object: When using data hooks like useTable, you can pass the schema property in the meta object to override the default schema. Here is an example:
// src/pages/users/list.tsx
import { useTable } from "@refinedev/core";

const tableProps = useTable<IUser>({
resource: "posts",
meta: {
schema: "custom", // Replace "custom" with your schema name
},
});

// src/pages/users/list.tsx
import { useTable } from "@refinedev/core";

const tableProps = useTable<IUser>({
resource: "posts",
meta: {
schema: "custom", // Replace "custom" with your schema name
},
});

3. Swizzle the Data Provider (if needed): If you encounter issues, you might need to swizzle the data provider to customize it further. This involves copying the implementation of the @refinedev/supabase's dataProvider and liveProvider into your project and modifying it to handle multiple schemas. Here is an example modification for the create method:
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,
};
},

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,
};
},

Additional Resources - Using meta to pass values to data provider (https://refine.dev/docs/data/packages/supabase/#schema---using-custom-schema) - Discussion on fetching data from multiple schemas (https://github.com/refinedev/refine/discussions/5094) By following these steps, you should be able to configure and use a custom schema with Supabase in your refine project. If you continue to face issues, it might be helpful to check the specific error messages and ensure that all configurations are correctly set. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@281353575504805888> kapa.ai is still learning and improving, please let us know how it did by reacting below
correct-apricot
correct-apricot2mo ago
@kapa.ai and what in combination with the antdinference?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To use a custom schema with Supabase in combination with @refinedev/inferencer and Ant Design, you need to ensure that the custom schema is correctly passed to the data provider and that the inferencer components are set up to use this configuration. Here’s how you can achieve this: Step-by-Step Guide 1. Configure Supabase Client with Custom Schema: Set up your Supabase client to use the custom schema as shown below:
// src/utility/supabaseClient.ts
import { createClient } from "@refinedev/supabase";

const SUPABASE_URL = "your_supabase_url";
const SUPABASE_KEY = "your_supabase_key";

export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
db: {
schema: "custom", // Replace "custom" with your schema name
},
auth: {
persistSession: true,
},
});

// src/utility/supabaseClient.ts
import { createClient } from "@refinedev/supabase";

const SUPABASE_URL = "your_supabase_url";
const SUPABASE_KEY = "your_supabase_key";

export const supabaseClient = createClient(SUPABASE_URL, SUPABASE_KEY, {
db: {
schema: "custom", // Replace "custom" with your schema name
},
auth: {
persistSession: true,
},
});

2. Pass Schema in Meta Object: When using inferencer components, you can pass the schema property in the meta object to override the default schema. Here is an example of how to do this:
import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";
import { ConfigProvider } from "antd";
import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";
import { AntdInferencer } from "@refinedev/inferencer/antd";

const API_URL = "<https://api.fake-rest.refine.dev";>
const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
create: "/samples/create",
edit: "/samples/edit/:id",
show: "/samples/show/:id",
},
]}
>
<Routes>
<Route
element={
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
}
>
<Route path="/samples" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/create" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/edit/:id" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/show/:id" element={<AntdInferencer meta={{ schema: "custom" }} />} />
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";
import { ConfigProvider } from "antd";
import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";
import { AntdInferencer } from "@refinedev/inferencer/antd";

const API_URL = "<https://api.fake-rest.refine.dev";>
const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
create: "/samples/create",
edit: "/samples/edit/:id",
show: "/samples/show/:id",
},
]}
>
<Routes>
<Route
element={
<ThemedLayoutV2>
<Outlet />
</ThemedLayoutV2>
}
>
<Route path="/samples" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/create" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/edit/:id" element={<AntdInferencer meta={{ schema: "custom" }} />} />
<Route path="/samples/show/:id" element={<AntdInferencer meta={{ schema: "custom" }} />} />
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

3. Swizzle the Data Provider (if needed): If you encounter issues, you might need to swizzle the data provider to customize it further. This involves copying the implementation of the @refinedev/supabase's dataProvider and liveProvider into your project and modifying it to handle multiple schemas. Here is an example modification for the ` ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@281353575504805888> kapa.ai is still learning and improving, please let us know how it did by reacting below