Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing SQLite3 database between multiple programs

I've begin building a web application using Flask and Flask-SQLAlchemy. My experience with building web applications is very limited so I apologize before hand if I am being ambiguous.

The database for the web application is already built by another program running on the server. So all the tables are already predefined in the database. My web app and the other program running on the server will have read & write access to the database.

Recently I've decided to restructure my application and cater toward the model-view-controller schema, similar to Django, and to use blueprints for making things more manageable and neater. Similar to this https://github.com/mitsuhiko/flask/wiki/Large-app-how-to

...
app_name/
    model.py
    view.py
    controller.py
    __init__.py
...

So I've done a few tutorials and read up on Flask-SQLAlchemy but what I can't make sense for the life of me is how do I define my models in the application if my database is already predefined by another program??. and How can I use the SQLAlchemy ORM with a predefined database?

Previously, before I decided to restructure, I just used Pyhton's sqlite3 library for grabbing stuff from the database and displaying it on the web page. It wasn't to pretty and the way I was structuring things things would have gotten out of hand fast.

like image 650
drewski Avatar asked Aug 24 '26 00:08

drewski


1 Answers

Does the other program also use sqlalchemy so that you can lift/share its models? If not, you could try reflection: http://docs.sqlalchemy.org/en/latest/core/reflection.html Or this experimental automap: http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html

And your question wasn't about this, but sqlite3 is a file database, not a client-server database. Not saying you will, but you may run into concurrency issues:

sqlite3 concurrent access

http://www.sqlite.org/lockingv3.html

The OS and filesystem plays a role in this.

like image 178
dcr Avatar answered Aug 26 '26 15:08

dcr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!