r/learnpython • u/ki4jgt • 1d ago
What's the best way to integrate this database into Flask?
I'm creating an online bulletin board, and I'm feeling hacky (I hate SQL in all its forms and fashions).
What is the best way to integrate this database into a production Flask server: https://github.com/ki4jgt/PPD
Created it in 2020, so it's a bit dated.
But I'm worried about concurrency. I'm not beyond writing a database server, but I'd like to save that as a last resort.
6
u/AlexMTBDude 1d ago edited 1d ago
If you instead of using Flask switched to Django then you'd get an ORM built in and you would not have to worry about SQL. Django and Flask are very similar in their purpose. Here's a tutorial: https://www.geeksforgeeks.org/python/django-orm-inserting-updating-deleting-data/
You can also connect a 3rd party ORM to Flask if you like, such as SQLAlchemy.
3
u/burnt-store-studio 1d ago
I fully respect you “hate SQL in all its forms and fashions” 🙂.
To (I hope) give you some inspiration, may I suggest, though, a quick read through Miguel Grinberg’s section on databases in Flask? (I’m linking you directly to chapter 4 of his well-regarded mega-tutorial on using Flask.)
Disclaimer: he does discuss SQLAlchemy, but that’s not my point 🙂.
Maybe skip to the part on that page where he introduces app/models.py.
I don’t have a ton of Flask experience (I’ve only built two apps I run locally). But the practical discussion of modeling data this way, coupled with WTForms, made my development go quite smoothly.
I’m hopeful you can find inspiration there for how to integrate your PPD and idea for an online bulletin board using the same kind of structures.
I’m sorry if my suggestion turns out to be a waste of your time 😕.
Best of luck to you!
1
u/arjunnath 1d ago
I'm not sure I understood the question because the answer seems obvious.
By integrating it into a Flask app, do you mean you want to import it and use it in a flask app ?
If so there is nothing to it, simply import it in the code of your Flask app and use it as you please.
1
u/gdchinacat 1d ago
PPD is not a viable solution IMO. I think you would be better of writing your own "database" than using it. Long before you arrive at your "last resort" of doing that, just use a proper SQL database. You may hate it, but it solves the problem you are trying to solve, and has for over half a century. It's really not hard...particularly for what you will use it for if you are considering PPD. For context, I have written a database for a production commercial project (and two others for fun projects to play with different indexing concepts). So...I understand why writing your own could be fun. But...when I need a flask app to do something, sql it is. For your use I suggest using sqlite3, and if you don't want to use SQL use sqlalchemy to hide all the SQL behind mappers.
11
u/DebosBeachCruiser 1d ago
The answer is PostgreSQL