Features | Comment |
---|---|
MongoDB Driver | PyMongo |
Using ODM | No |
Transaction Support | No |
Microservices Support | No |
This repo uses pymongo driver to connect to MongoDB. This repo contains three parts
- Django StartProject rest_api_template
- Orders App
- Shared Python Module
This python module contains three python files each does its own part of the job.
- database.py:
- This file contains the logic to instantiate the pymongo client
- Classes
MongoDBClient
singleton class that extendsObject
class,Collection
a static class that hasMongoDBClient
instance which creates collection based on Database name and collection name dynamically - It also has
OrderCollection
andProductCollection
classes which creates singleton classes that usesCollection
class to get the collection pointer for the database
- helper.py:
- This file mostly will have helper functions that makes our life easier
- wrapper.py:
- This file is created to house Helper classes to create Success or Failure responses
- This file contains three classes
Wrapper
class which has a data field to be set by the extending/implementing classesSuccessWrapper
class is used to build success responses,the data is provided by user, thesuccess=True
is given in the constructorFailureWrapper
class is built for error messages only
- Orders app contains the typical api logic with models, views and urls. It also has
custom_exceptions.py
file. - It contains two classes
DatabaseInitException
andRecordNotFound
exceptions classes. Both extendsException
class. models.py
file contains the type definitions forOrder
andProduct
. Usedmypy
library to have the typesutil.py
file contains the actual logic in which the app contacts the database file from shared python module