First, we define the generic method in the domain service class. Note that we supply defaults for the find() method arguments; that is, skip, limit, no_cursor_timeout, and cursor_type:
# sweetscomplete.domain.purchase
from sweetscomplete.domain.base import Base
from sweetscomplete.entity.purchase import Purchase
from bson.objectid import ObjectId
from pymongo.cursor import CursorType
class PurchaseService(Base) :
def genericFetch(self, query, proj = dict(), order = None) :
for doc in self.db.purchases.find(query, proj,
0, 0, False, CursorType.NON_TAILABLE, order) :
yield doc
# other methods not shown
As you can see from the following code, the onus for results processing is on the calling program. As with other demo scripts, we first establish imports and set up the connection:
# /path/to/repo/chapters/05/demo_sweetscomplete_purchase_sales_report.py
import os,sys
sys.path.append(os.path.realpath("src"))
import...