I have few tables in my ETL projects that are being loaded very frequently. I want to create a common module where all main modules can just call this common module, pass column values and insert data. In c#, to achieve this, we have properties defined for each column and table for a class.. What is the best way to achieve this in Python? can you guys share any good links?
Asked
Active
Viewed 112 times
0
-
1Are you looking for an ORM like [SQLALchemy](https://www.sqlalchemy.org/) or perhaps [SQLObject](http://sqlobject.org) ? – progmatico Apr 20 '19 at 21:18
-
Thanks @progmatico Is there a better example I can look at? Thanks. – SQLSERVERDAWG Apr 21 '19 at 03:29
-
is using getter and setter a right way to achieve this? Create a getter and setter for each columns, pass the object with values in my module and then call insert. – SQLSERVERDAWG Apr 21 '19 at 23:30
-
Not quite. You should do a quick search about why getters and setters aren't usually written in Python like in other languages (hint: nothing is really private, see also how Python properties are handy in many cases). About ORM's you should get into the spirit first. They allow you to define (or are able to deduce) a table correspondence for your Python objects. They ease the save and retrieval of objects into those tables in the DB and use SQL-like dialects, that look a bit like syntax sugar on top of SQL. – progmatico Apr 22 '19 at 13:48
-
Search for tutorials, like [here](https://www.pythoncentral.io/introductory-tutorial-python-sqlalchemy/). This looks a good introduction, don't know if it's updated. – progmatico Apr 22 '19 at 13:49
-
ORM's idea is to map your objects into tables for the relational model used by databases. And also abstract both from raw SQL and the specific DB engine you are using. And you keep using your objects in OO style, instead of fighting with SQL statements. Having to learn the ORM SQL variant is, well, a smaller annoyance given the benefits. – progmatico Apr 22 '19 at 13:54