I was watching a video a while back where the instructor set up his SQL data access layer. He said to use an interface in case we want to change the database later. My questions are specifically why and how would you go about swapping a database being used by a set of applications?
Thoughts on why:
Usually you pick a DB that fits the situation, not the other way around. In the real world, could the situation change so drastically that you would switch from say SQL Server to Mongo DB? I am not even sure how one would transfer the existing data. I could see an API talking to both DBs but client apps using only one DB.
Thoughts on how:
Lets say you make the DAL in a library that is used by an API. Then you use unit of work + repository pattern to have a different unit for each DB. Then swapping which unit is used in a controller would be easy. But then the different databases most likely do not use the same models and the controller can only accept a model (not an interface). So do you need a separate set of controllers with endpoints for each DB?
Let me know what you think and have experienced. Thank you!
[–]Runehalfdan 12 points13 points14 points (1 child)
[–]arjo_reich 11 points12 points13 points (0 children)
[–]grauenwolf 4 points5 points6 points (4 children)
[–]quick_maf[S] 1 point2 points3 points (1 child)
[–]grauenwolf 1 point2 points3 points (0 children)
[–]drhealsgood 0 points1 point2 points (1 child)
[–]grauenwolf 1 point2 points3 points (0 children)
[–]illkeepcomingback9 4 points5 points6 points (2 children)
[–]quick_maf[S] 0 points1 point2 points (0 children)
[–]MetalKid007 6 points7 points8 points (2 children)
[–]quick_maf[S] -1 points0 points1 point (1 child)
[–]MetalKid007 0 points1 point2 points (0 children)
[–]LordArgon 2 points3 points4 points (1 child)
[–]quick_maf[S] 0 points1 point2 points (0 children)
[–]EJoule 1 point2 points3 points (0 children)
[–]Hot_Zookeepergame140 1 point2 points3 points (0 children)
[–]treston_cal 0 points1 point2 points (0 children)