0

Using pgdb connection I am passing SQL to get results into a DF which are further processed. As the module grows, python class (queries.py below) that keeps track of all the SQL is growing longer and longer. Any suggestions how to handle it as it grows longer and longer?

connection.py

import pgdb
class DBConnect:
    def __init__(self, host, dbname, user, password):
        pgdb.connect(host=self.host, database=self.dbname, user=self.user, password=self.password)
    ....

queries.py

class Queries():
     def __init__(self):
         return
    
     def sql1(self):
         return '''select column from ...'''
     
     def sql2(self):
         return '''select column from ...'''
     ....

some_module.py

import queries
import connection
import pandas

query = queries.Queries()
connect = DBConnect(host, dbname, user, password)
sql1results = pd.DataFrame(connect.executeQuery(query.sql1))

def do_something():
    ....
Community
  • 1
  • 1
SaM
  • 43
  • 6
  • What exactly is the problem you're trying to solve? Exactly how big is your `Queries` class? Is the size causing problems? – larsks Aug 13 '19 at 02:20
  • Its redundant for the most part as each time I create a new module for a use case I do the exact same thing import connection and import queries and return DF to processes. I am sure there is a better way than writing a class that has bunch of defs with just a SQL in it to return kind of like old school procedural. – SaM Aug 13 '19 at 02:38
  • Also the functions/SQL is anywhere between 4 lines to 50 lines and I have about 30 such functions and might keep growing. – SaM Aug 13 '19 at 02:39

0 Answers0