GithubHelp home page GithubHelp logo

Comments (14)

zachgrayio avatar zachgrayio commented on April 25, 2024 10

@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

from nest.

zachgrayio avatar zachgrayio commented on April 25, 2024 2

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?

from nest.

rynop avatar rynop commented on April 25, 2024 2

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

from nest.

rynop avatar rynop commented on April 25, 2024 1

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)

from nest.

juandav avatar juandav commented on April 25, 2024

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

from nest.

Mark-McCracken avatar Mark-McCracken commented on April 25, 2024

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

from nest.

cojack avatar cojack commented on April 25, 2024

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

from nest.

GulajavaMinistudio avatar GulajavaMinistudio commented on April 25, 2024

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

from nest.

silvelo avatar silvelo commented on April 25, 2024

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

from nest.

cdiaz avatar cdiaz commented on April 25, 2024

This is another example of Nest/Iridium by @AngelMunoz

from nest.

JulianBiermann avatar JulianBiermann commented on April 25, 2024

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

from nest.

kamilmysliwiec avatar kamilmysliwiec commented on April 25, 2024

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

from nest.

vrilcode avatar vrilcode commented on April 25, 2024

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?

from nest.

lock avatar lock commented on April 25, 2024

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.

from nest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.