Have u placed the db file in the proper directory? I mean both the app.py and db file should be in the same directory and also it’s important to commit and close db operations.
Not always but it depends how your giving the path. If you are giving the right path then there will be no issues. Once check how are giving the path from app.py !
I use utils.py where I can declare all my methods. Utils.py located in a folder called src. That is a folder placed in root directory of app where we have a app.py
Now in utils.py I have a method called load_data()
def load_data() → pd.DataFrame:
“”"
These function query the database and return all records as a DataFrame
returns pd.DataFrame(all_records)…
“”"
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(file)))
db_path = os.path.join(root_dir, “data”, “madurai.db”)
with sqlite3.connect(database=db_path) as con :
statement = “SELECT * FROM donation_records;”
df = pd.read_sql_query(statement,con, index_col=“id”)
return df
Hey @Nagarjun , the logic is correct but how you are calling this in your app.py file?
Also instead of using the os module you can directly use
sqlite3.connect(‘madurai.db’) because you are in the src folder and you can easily call this as
from src.utils import function_name in app.py file