As with our entity classes, we start by defining a base class for all the domain services. What the base class provides for us is a property that represents instances of pymongo.database.Database and db.mongodb.connection.Connection.
The constructor initializes these two properties using the connection to retrieve the database instance:
# sweetscomplete.domain.base
class Base :
db = None
conn = None
def __init__(self, conn, database) :
self.conn = conn
self.db = conn.getDatabase(database)
We then define a domain service class called sweetscomplete.domain.product.ProductService that inherits from the base class:
# sweetscomplete.domain.product
from sweetscomplete.domain.base import Base
from sweetscomplete.entity.product import Product
class ProductService(Base) :
# useful methods definitions go here
We are then free to add useful methods as needed. These methods are wrappers for core pymongo collection methods including...