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)
- Wrong `Object` prototype in repl context HOT 3
- MongoDB ParseObjectIdPipe or ObjectIdPipe validation for NestJS HOT 4
- Consider supporting reflect-metadata@^0.2.1 HOT 5
- perf: Proposal - Should we evaluate to use Fastify by default instead of Express? HOT 2
- 'version' specification is not working in global prefix excluded routes HOT 1
- NestJS CLI MODULE_NOT_FOUND with Docker HOT 3
- Issue with reflect-metadata v.0.2.1 when using @nestjs/axios HOT 2
- MQTT payload parser crop data HOT 1
- Problem with Websockets receiving data from 3rd party service HOT 1
- After upgrading from 9.4.3 to 10.3.0 I get "TypeError: Cannot read properties of undefined (reading 'values')" at startup HOT 5
- The `roodDir` compiler option not being respected when using SWC HOT 2
- functional hooks for context injection HOT 8
- How to receive Long or int64 type parameters HOT 1
- WebSocketServer decorator gives unexpected value
- If I was developing in pure js how would I use a function decorator and now I use a function decorator that starts with an error like @UploadedFile() HOT 2
- Monorepo only builds root project when builder set to swc HOT 2
- Support Javascript in Resource schematic HOT 3
- FastifyAdapter can't take a FastifyInstance due to a type error HOT 6
- Add Predefined Http Exceptions for each http status code HOT 1
- perf: Why nestjs install typescript in production dependencies? HOT 1
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.