As mentioned in this post. NestJS's schematics new feature able to generate CRUD easily, but the generator is generic and not related to any ORM.
How can I connect the generated CRUD by schematics with TypeORM?
Related
I have a few models in my DB. I wanted to know if there is a way to auto-generate the code to apply CRUD operations on them - especially for those that have foreign keys.
Not sure, if I get your question right. With prisma generate you can generate javascript API to run CRUD operations against your database.
If you want to generate a RESTful API with CRUD operations, take a look at e.g. https://github.com/kepelrs/nestjs-prisma-crud (requires Nestjs).
We're very familiar with IBM's Loopback and we're exploring/comparing NestJS as an alternative.
First and main topic: One feature that has always been an overall pleasure to work with is Loopback's built-in REST API's for its models together with the GraphQL-like querying that is supported both in the TypeScript API and as part of the REST API's themselves. It's been a pleasure to be able to include as many levels of depth of related entities as we like, add in other filtering and limit/scope to include certain fields. (This gives a gist of the feature: https://loopback.io/doc/en/lb4/Include-filter.html)
Is this possible to achieve in the NestJS world? I see a RelationalQueryBuilder for NestJS that is built-in (https://orkhan.gitbook.io/typeorm/docs/relational-query-builder) but I don't see it connected to a built in REST API and it looks a bit less sophisticated with its relations querying capability. Here are some decorators for CRUD REST in NestJS, but without the querying support (https://github.com/nestjsx/crud/wiki/Controllers#api-endpoints).
Also mature polymorphic relations support in Loopback seems like a strong differentiator for Loopback vs. an emerging extension for polymorphic relationships in NestJS (https://github.com/bashleigh/typeorm-polymorphic... thank you bashleigh!). Any success/thoughts opinions here?
How is working with MongoDB with NestJS (and TypeORM or Mongoose are the options)?
It seems like the first feature and main topic (built-in REST API's with fluent querying) may be one that really sets Loopback apart.
I started an angular/express project some weeks ago. I found knex.js and was using it for seeding/migrations and then I realized I could use it's query builder to perform the CRUD operations as well. I think my last missing piece is an ORM. I'm looking for a widely used library that can generate the DB tables into JavaScript objects so I don't have to do it from scratch / continuously modify as I build, does anyone have any suggestions?
Thanks!
Here are some ORMs, you can use them to create the model classes for application based on the DB tables.
Sequelize
TypeORM
I have a one file which has details of the database named xyz.js and another file which created the database using that file in mongodb and also has various functions like adding to database etc.The name of this file is create.js. Now I want to convert create.js code using mongodb to waterline.
me_aj, there is no possible short and simple answer for what you want. Nor there is any tool that will do what you need. Here are some pointers for what you'll need to do.
1. Learn about using waterline
It may sound obvious but you should start by getting acquainted with waterline and the best places are the waterline project and the Waterline Docs.
By then you'll know waterline is an adapter based ORM and that you'll have to decide which adapter to use. If you are using mongodb, you are probably looking at sails-mongo.
2. Config waterline to connect to the desired data store
Waterline, contrary to some other ORMs, has to be initialised before you can start using it. If you are using it outside sails you should look at these examples on how to set up a simple app. You'll also need to configure it by following the specific adapter settings. If you are connecting to mongodb check the instructions on the sails-mongo project.
3. CRUD operations
By now you've setup waterline to initialise and connect to your chosen data store, now it's time to do things with it. Similar to many other ORMs. waterline uses methods such as find, update, create and destroy to perform CRUD operations, to learn more about using these check the query methods documentation page.
This should be enough to point you in the right direction.
I am developing a sails.js app. In my previous sails app, I used MySQL with the default waterline ORM. I am planning to use Mongodb in my new app. I have come across limitations with waterline, one of them being, querying an association. My current app is logically intense and deals with a lot of statistical data. Is it safe to continue with waterline or replace it with Mongoose?
Waterline is getting better and supports for many features that were missing lately. Since both have association support now, any of them would be fine for this task. Only advantage is Waterline is that if the project is based on Sails, using it would be much easier.
Waterline associations
There is an example on Github for a Mongoose ORM Hook that should facilitate the disabling of Waterline and other associated hooks and enabling Mongoose as the ORM to use in your apps.