Hello everyone,
I’ve been learning various CS topics for few years now and Streamlit has been really helpful to me. Lately I’ve been trying to learn more about databases in general. Here’s the issue I’ve encountered:
I’d like for users to be able to load their own sqlite database with file_uploader. Once it’s loaded, the app would connect to it, fetch some data, adjust it with pandas and show it to the user. The user could then change it with data_editor, insert it into the database and download it.
The issue is that when I try to pass the file_uploade object into the connection I don’t get anything in return. The database I’m uploading works normally when I coonnect to it locally.
Is what I’m trying to do doable without saving the database to a tmp folder? Is it considered bad practice?
Here’s the code:
import streamlit as st
import sqlite3
user_db = st.file_uploader("Upload your database", type=".sqlite3")
if user_db is not None:
connection = sqlite3.connect(user_db.name)
cursor = connection.cursor()
cursor.execute("SELECT * FROM sqlite_master;")
data = cursor.fetchall()
st.write(data)
connection.close()