I have this in my main execution file:
databaseUrl = appPath + '/db/timey.db'
which is pointing to my SQLite DB.
I have done some encapsulation for accessing my model (Data/DB). So until databaseURL finally gets used I would need to pass it from main -> view.py -> model.py -> db.py.
This would be stupid because e.g. my view class doesn’t need to know about my database or its path. So what would be a proper approach to actually make this path “globally” accessable without passing it around all the time?
I tried to make databaseUrl global, but I don’t like the idea and haven’t really gotten it to work like that anyway.
Storing the information in an external file would be an overkill, as it is the only (constant!) global used variable anyway.
Thank you!
I don’t think storing it in an external file would be overkill at all. I think it is helpful to have a settings or config file
etc.
This is what django and scrapy do to store a projects database config settings, and all other project settings
Also, if you have a database class it might make sense to store these settings inside of it? I don’t know.
The settings.py file let you easily set up a development / local database urls.
TO do this you can have a
local_settings.pyfile that will never be put under version control or packaged in your projectin your settings.py file
then in local_settings.py you can override the DATABASE_URL to be your dev database!! This is a django project convention