I’m trying to migrate my ExpressJS with Postgres code to NestJS but it’s recommending me to use an ORM and use Typeorm. I’m hearing bad things about typeorm like it’s not maintained with a lot of open issues and buggy. My code is right now written in pure Postgres SQL and wondering if it’s worth learning typeorm because I don’t want it dead right when I finish learning it. What should I do?
#need help finding an ORM while migrating to NestJS
1 messages · Page 1 of 1 (latest)
Maybe u can try with DrizzleORM
There’s no NestJS for drizzleorm though
And I need a pg-cron like thing so I can schedule queries
Is it worth learning typeorm?
You will "learn" typeorm in a few minutes so pretty much yes, the actual question is "is it worth it to convert my raw queries to an ORM", the answer being "probably if performance isn't crucial to you"
I feel like sequelize is more stable and that I should learn that instead. Or should I just use raw sql with NestJS?
Once you've learn an ORM they pretty much all look the same
Start with one or the other and see how it goes
You will have a decent picture of where you go in less than a few hours
I'd suggest starting with TypeORM. It is very good when it comes to basic CRUD operations and that's usually what you'll need from an ORM. I dont personally like to use features like query builders, or doing low level stuff with ORM. Any time you need to do something complex, use raw queries. And in my opinion TypeORM has a better typescript support than Sequelize. Sequelize was initially designed for only javascript and now they are trying to make it compatible with typescript as well
I’m having trouble deciding on typeorm, drizzleorm, or, sequelize. I just can’t make my decision and find a good tutorial.
Best is the enemy of good, just pick one that seems all right to you and your needs and go for it
The fact that it's hard to decide between them just show how close they are in terms of features
You can always easily change later as syntax is quite similar anyways
Should I go with sequelize?
Is it a joke or you didn't read what I just write?
I meant to write I’m going with sequelize
Ok I use Sequelize in some of my projects and I find it more clear than Typo
Again the switch from one to the other is quite easy if you ever change your mind
I’m used to using raw sql so ORMs are new to me.
Mikro orm is probably the best out of all if you are looking for active record imo
TypeORM is very limited when it comes to associations
For example, you can't fetch softDeleted rows of an association, you need to perform a separated request, or use query builder. But in my mind, querybuilder is not a good way to perform using an ORM.
I really don’t want to convert my raw sql to an ORM when migrating from express to NestJS and I also make use of pg_admin.
Is it still worth migrating from express to NestJS?
It depends of your usecase. I find it very worth at my point, because of the guard system, and all of the features available via Nest modules, Typescript, etc.
if you make use of repositories, there should be no need for an orm, you can wrap your raw sql queries in the repository
I suggest against TypeORM as it is abandoned, and It has never reached v1.x.x release
Haven't tried it yet, but MikroORM seems promising, and is under active development
It is not abandoned but really slow in development
How do I do this? Is there an article?
I personally just started using Kysely. Its just a query builder that wraps around your db calls. It works so well with typescript. That combined with using kysely-codegen to generate types based on your DB schema means you get type safe queries and get to avoid the headache of managing entities.
I always recommend using the repository pattern to separate your database calls from your services/controllers.
https://www.geeksforgeeks.org/repository-design-pattern/
This is a good breakdown of the repository pattern that may be helpful
If they'd only stop leaving out oracle
gee why use oracle if not bcuz of legacy
quod erat demonstrandum
still trying to find ppl that use it for other reasons x)
Dis microorm reached to the level of typeorm?
Typeorm's bar is actually pretty low. It's used a ton, Nest has it as its main orm for some reason, but it's a half-dead project with a ton of unresolved github issues.
Mikroorm is actively developed, and issues are solved (although by a single developer), and it's main design pattern (a static class with decorated properties) is the same as in Typeorm - and this leads to an ideal and seamless integration with Nestjs
Sorry coulnt send the message as it was blocked
My experience with Typeorm was that it was used in a project I worked on in 2022, we encountered a bug that seemed pretty basic at the time (don't remember the specifics sadly), looked at github, and saw that the issue for that was open for a few years. Left a really bad impression. The project was soon abandoned for unrelated reasons.
After that I just resolved to not use it anymore, and looked for something else when I was to build another project. I agree with your points on prisma (at least on not wanting to write the models in a different language) and Drizzle (not sure it sucks, but it's definitely not how you want to do things in Nest).
When I discovered Mikroorm, it just seemed to me like Typeorm with a bit cleaner syntax and with a steady stream of updates and closed issues. Never had an issue. Though I mostly build simple microservices, so it's not like I'm going to encounter complex sql queries.
You probably won't know for sure unless you try, but I really doubt there's anything in typeorm that Mikroorm does not have
@robust berry
Oh i see
Does it has virtual column?
https://mikro-orm.io/docs/defining-entities#formulas
Does this cover that?
https://mikro-orm.io/docs/virtual-entities whole entities too if you need
Virtual entities don't represent any database table. Instead, they dynamically resolve to an SQL query (or an aggregation in MongoDB), allowing to map any kind of results onto an entity. Such entities are meant for read purposes, they don't have a primary key and therefore cannot be tracked for changes. In a way they are similar to (currently un...
Can mikroorm do computed columns?
I think these are the exact things that I linked in the post above