SiddhantSadangi / st_supabase_connection

An easy-to-use Supabase connector for Streamlit that caches your API calls to make querying fast and cheap.
https://pypi.org/project/st-supabase-connection/
MIT License
91 stars 12 forks source link

Queston/Feature Req : How can we access custom schemas using this wrapper #10

Closed phreakyphoenix closed 9 months ago

phreakyphoenix commented 9 months ago

Thanks for building this Siddhant. I'm trying to do access a custom schema using this lib.

I think it is possible with supabase-py as described here, but haven't tried myself.

Is it possible to access a custom schema using st-supabase-conenction, if so where do I declare the schema name? It would be helpful to add this bit to the database section in the docs.

SiddhantSadangi commented 9 months ago

Hello @phreakyphoenix! 👋

You can use a wrapper to access custom schemas. However, as of now, you cannot pass options to create_client() using this wrapper. In order to update the schema on the postgrest client, you can use the code below:

st_supabase = st.connection(name="supabase_connection", type=SupabaseConnection)
st_supabase.client.postgrest.schema("YOUR_SCHEMA_NAME")

Let me know if you have any other questions.

phreakyphoenix commented 9 months ago

Thank you so much worked like a charm.

There's one gotcha,

we'd need to redeclare st_supabase.client.postgrest.schema("YOUR_SCHEMA_NAME") before making each table fetch

not sure why, otherwise supabase complains table doesn't exist on public schema, even though the other schema is defined just a few lines above. We can skip it for consecutive st_supabase commands though (without anything else in between like try except etc.) Mentioning it here in case someone else faces this. This happens when using declaring st_supabase both with and without st.session_state.

SiddhantSadangi commented 9 months ago

@phreakyphoenix , I am not able to reproduce the behaviour you mentioned.

I ran multiple fetch statements on a custom schema, both with and without non-st_supabase commands between them and both on same and different tables, and got the results from the custom schema everytime without having to redeclare it.

Could you share a code snippet for me to be able to reproduce this?