I am creating a query builder class that will help in constructing a query for mongodb from URL params. I have never done much object oriented programming, or designed classes for consumption by people other than myself, besides using basic language constructs and using django's built in Models.
So I have this QueryBuilder
class
class QueryHelper():
"""
Help abstract out the problem of querying over vastly
different dataschemas.
"""
def __init__(self, collection_name, field_name, params_dict):
self.query_dict = {}
self.params_dict = params_dict
db = connection.get_db()
self.collection = db[collection_name]
def _build_query(self):
# check params dict and build a mongo query
pass
Now in _build_query
I will be checking the params_dict
and populating query_dict
so as to pass it to mongo's find()
function.
In doing this I was just wondering if there was an absolute correct approach to as whether _build_query
should return a dictionary or whether it should just modify self.query_dict
. Since it is an internal method I would assume it is OK to just modify self.query_dict
. Is there a right way (pythonic) way of approaching this? Is this just silly and not an important design decision? Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…