I Want to make my microservice compatible with both relational and non-relational databases,
Currently, I have five small modules which make a single microservice:
Controller-module - This contains all my controllers and has a dependency on the service module
Service module - This contains services which communicate with DB layer to get data or post data, and obviously has a dependency on data layer (common-db-modules)
Common-db-modules- this module defines contracts (interfaces only) for datalayers to follow in order to be compatible with service
Data-layer - this module provides concrete implementation of contracts defined by common-db-module. There could be multiple data-layers depending on the database. which means one for Mongo DB, one for MySQL, etc
Packaging: number of packaging module is defined based on db used, packing packages
- controller-module
- Service-Module
- One Data-Layer (DB for which this packaging is made)
My question: is there a way to eliminate this common contract for DB and have a single implementation of the Data layer which will serve both relational and non-relational DB?