0

Recently i started to use flask and I liked pretty much. In the past I had a system in PHP with a lot of databases like marketing, HR, finance and so on. Each of this databases had their own tables like HR used to have employers, companies and so on.

Each of this tables was a class in PHP, we used this system to facilitate save/delete since they were used all over the system all we had to do was instantiate a new object from one of the table/class where which column was a object property and then call $obj->Save() to insert a new row in the table.

Programming has evolved so much since then so my doubt is if there's a more efficient way to do that in python/flask, instead of creating a class for each of the tables from the databases like I used to do in PHP, I know this is a large question so I would appreciate recommendations of books, wikis and so on about this topic.

  • Hey there! Stack Overflow questions asking for opinions go against site guidelines. See [How To Ask][https://stackoverflow.com/help/how-to-ask]. Instead, post a specific question, with code sample, explaining clearly what the problem is. – DV82XL Mar 07 '21 at 19:01
  • @DV82XL i'm not asking for opinions i'm asking what's the best way to handle large system with large databases in python/flask – ariclenes ferreira Mar 07 '21 at 20:20
  • You're asking for "recommendations of books, wikis and so on", which goes against SO guidelines. I didn't write them. I'm just letting you know. Please read [What topics can I ask here?](https://stackoverflow.com/help/on-topic), it will help a lot, trust me. – DV82XL Mar 08 '21 at 00:21

1 Answers1

0

A fairly modern approach to interface with a database in high-level programming languages is to use an ORM, or Object Relational Mapper. See this Stack Overflow thread for a good explanation.

If you are using Flask, SQLAlchemy is the most popular choice, so much so that Flask actually has an extension called Flask-SQLAlchemy. Keep in mind, that you will still be mapping classes to database entities. However, the power of SQLAlchemy is that it provides a higher level of abstraction on top of the database, which can go beyond simply mapping a class to a table row. According to the documentation:

SQLAlchemy considers the database to be a relational algebra engine, not just a collection of tables. Rows can be selected from not only tables but also joins and other select statements; any of these units can be composed into a larger structure. SQLAlchemy's expression language builds on this concept from its core.

This Stack Overflow thread provides more Python ORM suggestions.

DV82XL
  • 5,350
  • 5
  • 30
  • 59