Python Forum

Full Version: Object Oriented DB Interactions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently I use xlrd xlwr with psycopg2 to move transaction records in and out of spreadsheets and postgres. That works but I am interested in learning OOP and it seemed like I could incorporate OOP in my current work. My question to the forum is whether or not that really makes sense practically?

My idea is to create a transaction class:

class transaction:
with attributes that map to the column headings for each spreadsheet. So each transaction would have a date transaction.date(), amount transaction.amount(), account transaction.account() and so forth. Further, I could create methods such as selects, inserts and updates which would retrieve, create and modify those transaction records.
This post was made prematurely due to some confusion with the tab keys. I will repost.
Currently I use xlrd xlwr with psycopg2 to move transaction records in and out of spreadsheets and postgres. That works but I am interested in learning OOP and it seemed like I could incorporate OOP in my current efforts My first question to the forum is whether or not that really makes sense practically?

My idea is to create a transaction class:

class transaction:
     def__init__(self,date,account,amount,theater,sales_num):
           self.date = date
           self.account = account
           self.amount = amount
           self.theater = theater
           self.sales_num = sales_num

with attributes that map to the column headings for each spreadsheet / DB table. Further, I could create methods such as selects, inserts and updates which would retrieve, create and modify those transaction records.

I can't imagine this hasn't been done with more knowledge and skill than I have so, assuming this approach makes sense, I was hoping the forum could provide some coaching on the pros and cons and possibly best strategy of this approach.

Best,

Hagen