Hi folks, a general question about db connections. I am using duckdb and motherduck for data storage , is there anything that might go wrong with storing the connection as a session state object?
I understand there is st.connection, but there’s no duckdb connection out of the box, and I am not sure if the overhead for setting up a duckdb connection via st.connection is worth it? Any thoughts?
a related question about how streamlit works : storing the connection should persist the connection through re-runs, what does st.connection provide that session state doesn’t when it’s an in process database like duckdb?
thanks @dataprofessor. I have connected to motherduck as described before. My worry, however, is with how streamlit’s execution model works with data connections? does a connection gets re-created every time the script reloads? would that cause issues? If the db is read_only , that won’t be a problem. But I do need to write and update tables.
do you know if the ‘con’ variable will point to the same db connection and I am not just re-initiating a connection every time? will either be problematic? without explicitly closing it?
hence why I was thinking of having the db connection as a session state object, can you think of any issues with that approach? or are we pretty safe either way?
Thanks Again!
p.s. I really enjoy your youtube channel, thanks for the great videos!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.