使用 pgdb 连接,我传递 SQL 以将结果放入 DF 中,然后进一步处理。随着模块的增长,跟踪所有 SQL 的 python 类(下面的queries.py)变得越来越长。随着它越来越长,任何建议如何处理它?
连接.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)
....
查询.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():
....