Comments (14)
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.
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.
@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.
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.
Hi, @GulajavaMinistudio , you can see on next sample. https://github.com/cdiaz/nestjs-demo
from nest.
I have an example I've managed to hook up to MySQL, will try to post tomorrow evening
from nest.
@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.
Any news about it ? and more docs about database integration in Nest ? so we can use and testing it in real project.
from nest.
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.
This is another example of Nest/Iridium by @AngelMunoz
from nest.
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.
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.
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.
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)
- I have a question about dependency injection and module import HOT 1
- Supply time to TypeOrmLogger.logQuery() HOT 1
- TCP.onStreamRead (node:internal/stream_base_commons:217:20) HOT 1
- RabbitMQ Bug Microservices HOT 1
- nx 18 + nest + webpack + serverless breaking with error src/main.handler is undefined or not exported HOT 1
- NestJS doesn't handle "Operation failed: QueueDeclare" error from amqplib HOT 1
- Problems Encountered with NestJS and pnpm in a Monorepo Setup HOT 1
- grpc microservice stops listening to requests after version 10.3.3 (needs peer dependency) HOT 1
- perf: caching return value for some functions HOT 1
- The request body does not return an object whose value is an array of objects
- Jest spy doesn't work on Microservices Controller (EventPattern) E2E Tests
- Feature Request: Support for Bun.js HOT 1
- Multi-tenant app fail on first non durable tree request HOT 2
- Kafka Microservice Error When Consumer Has Not Joined the Consumer Group
- LoggerService transforms the instance of Error when controller throws an Error HOT 3
- Easy way to compose ORed validators HOT 1
- Not sure if it is bug or feature request, nest middleware in jest runs before any other express middleware HOT 2
- Devtools with microservices: Error: listen EADDRINUSE: address already in use :::8000 HOT 4
- Hooks in global module which imported more than twice might called multiple times HOT 2
- Overide providers from imported module (not in testing context) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest.