#Adapting from a database (any ORM) vs. InMemory

4 messages · Page 1 of 1 (latest)

zenith junco
#

Development of the theme:
Some implementations, like addons in NestJS, switch the Service provider of the database in the Module. For example: https://www.npmjs.com/package/@nestjs-addons/in-memory-db

I personally disagree. Why?
In the development scenario, it may make sense, but what about a test that uses only inMemory? Would we have to add an "if" statement in every Module? Or validate NODE_ENV in every service? It doesn't seem to have good maintainability for other scenarios besides the current development.

What do I consider correct?
As shown in the image I sent, I believe it would be more appropriate to have a database configuration file (in the image: Kernel) that states: "We are using (prisma | typeorm | etc.), or we are using inMemory." If we want to change only the InMemoryService of one controller, it should be enough to modify it in the Module (Dependency Injection).

Considerations:
1 - Do not take ORM into account at this moment.
2 - Do not consider that we can deploy the containers to Github Actions for testing.
3 - Do not consider end-to-end tests in containers.

tawny glacier
#

Some implementations, like addons in NestJS, switch the Service provider of the database in the Module.

They don't "switch". They offer an alternative. And it's also not for proper database services, but rather for prototyping and mocking.

From that module's docs:

This provides a great way to quickly get up and running with prototypes and mock backends.

This kind of solution is very good for e2e testing, btw. as it lowers requirements to have a running database server to test with. There is also something very similar for MongoDB which I also use for e2e testing called mongo-memory-server. https://github.com/nodkz/mongodb-memory-server

tame storm
zenith junco