Are there any clear docs about how to connect and run crud operation with database, i.e mongodb, mysql, or postgree?
Hi, @GulajavaMinistudio , you can see on next sample. https://github.com/cdiaz/nestjs-demo
I have an example I've managed to hook up to MySQL, will try to post tomorrow evening
@GulajavaMinistudio,
I've integrated TypeORM with Nest rather successfully which allows me to use pretty much any relational database I want in a Nest application.
Here's a link to the example repository: https://github.com/zachgrayio/nest-typeorm-example
@zachgrayio would be awesome if you would like to improve docs (pr) for a guide with TypeORM and Nest , as you have already done this and have knowledge about it.
Any news about it ? and more docs about database integration in Nest ? so we can use and testing it in real project.
I know this is a pretty hot topic right now, and I'll try do something more on it as soon as possible.
I've made a few improvements to database components shown in the example above for use in internal projects, but haven't gotten that back into the example repo yet, and I'm not sure whether it's best to invest time in
a) updating the example
b) trying to work on some docs on a DIY integration
c) stand up a Nest TypeORM module people can get off of npm and start injecting into services.. this would require buy in from the nest guys though obviously
Any opinions?
I am working in two repo with iridium for mongodb and nest, and it worked well.
repo
Why iridium and not typeorm (mongo driver), beacuse iridium implements features near to mongoose, like validate and other nice stuff
This is another example of Nest/Iridium by @AngelMunoz
In order to ease the use of mongoose in my projects I created a small helper lib for injecting mongoose models.
Hi everyone
TypeORM - https://docs.nestjs.com/recipes/sql-typeorm
Mongoose - https://docs.nestjs.com/recipes/mongodb
Sequelize - https://docs.nestjs.com/recipes/sql-sequelize
Anyone have a TypeORM with an example of at least the C of CRUD? Currently only R is documented. Full CRUD example would be nice, but I think a Create example would show noobs like myself how to combine a DTO and Entity the CORRECT way in a POST endpoint.
https://github.com/kamilmysliwiec/nest-typeorm-example/blob/master/src/modules/employees/employees.controller.ts from @kamilmysliwiec is close, however it does not incorporate DTO. For example the required JSON attrs for update may be different than those for create - and we want to have data validation.
Making the entity.ts the DTO and the interface wont work, because AFAIK, you can't dynamically change the data validation on a class (ex a tags
attr may be required on Create, but not on Update, one entity class cant gracefully handle both these scnearios)
The RD of CRUD is not that hard, but a best practice for CU would be really helpful. It somehow unclear how to use Nest and TypeORM in real world scenarios.
@rynop Have you found something?
@cvh23 I have. Under the gun on timeline right now, will contribute back an example when I get time.
In short I just use a .dto
and a TyoeORM entity
and then use plainToClass
to transform the DTO to the entity class (this does not make sense for EVERY use case, but does for some). Ex:
import { plainToClass } from 'class-transformer';
...
const user = plainToClass(User, createUserDto);
I let the DTO do the data validation that is sent to the endpoint (ex: validating the body POSTed to /users).
I know this is super brief and not sure if it is best practice. Really need a sample project to convey. I will do my best to create one and contribute back when I get time.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@GulajavaMinistudio,
I've integrated TypeORM with Nest rather successfully which allows me to use pretty much any relational database I want in a Nest application.
Here's a link to the example repository: https://github.com/zachgrayio/nest-typeorm-example