nest icon indicating copy to clipboard operation
nest copied to clipboard

Documentation about CRUD with MongoDb and MySQL

Open GulajavaMinistudio opened this issue 9 years ago • 14 comments

Are there any clear docs about how to connect and run crud operation with database, i.e mongodb, mysql, or postgree?

GulajavaMinistudio avatar May 06 '17 06:05 GulajavaMinistudio

Hi, @GulajavaMinistudio , you can see on next sample. https://github.com/cdiaz/nestjs-demo

juandav avatar May 06 '17 12:05 juandav

I have an example I've managed to hook up to MySQL, will try to post tomorrow evening

Mark-McCracken avatar May 06 '17 21:05 Mark-McCracken

@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 avatar May 07 '17 17:05 zachgrayio

@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.

cojack avatar May 11 '17 08:05 cojack

Any news about it ? and more docs about database integration in Nest ? so we can use and testing it in real project.

GulajavaMinistudio avatar May 11 '17 14:05 GulajavaMinistudio

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?

zachgrayio avatar May 11 '17 22:05 zachgrayio

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

silvelo avatar Jun 23 '17 22:06 silvelo

This is another example of Nest/Iridium by @AngelMunoz

cdiaz avatar Jul 30 '17 03:07 cdiaz

In order to ease the use of mongoose in my projects I created a small helper lib for injecting mongoose models.

https://www.npmjs.com/package/nest-mongoose

JulianRuhrDev avatar Sep 28 '17 08:09 JulianRuhrDev

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

kamilmysliwiec avatar Oct 01 '17 21:10 kamilmysliwiec

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)

rynop avatar Aug 31 '18 13:08 rynop

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?

vrilcode avatar Sep 06 '18 14:09 vrilcode

@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.

rynop avatar Sep 06 '18 15:09 rynop

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.

lock[bot] avatar Sep 24 '19 14:09 lock[bot]