#need help finding an ORM while migrating to NestJS

1 messages · Page 1 of 1 (latest)

unkempt narwhal
#

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?

topaz horizon
#

Maybe u can try with DrizzleORM

unkempt narwhal
#

There’s no NestJS for drizzleorm though

#

And I need a pg-cron like thing so I can schedule queries

unkempt narwhal
#

Is it worth learning typeorm?

solemn sinew
# unkempt narwhal 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"

unkempt narwhal
#

I feel like sequelize is more stable and that I should learn that instead. Or should I just use raw sql with NestJS?

solemn sinew
#

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

mossy ingot
#

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

unkempt narwhal
#

I’m having trouble deciding on typeorm, drizzleorm, or, sequelize. I just can’t make my decision and find a good tutorial.

solemn sinew
#

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

unkempt narwhal
#

Should I go with sequelize?

solemn sinew
unkempt narwhal
#

I meant to write I’m going with sequelize

solemn sinew
#

Again the switch from one to the other is quite easy if you ever change your mind

unkempt narwhal
#

I’m used to using raw sql so ORMs are new to me.

bleak orbit
#

Mikro orm is probably the best out of all if you are looking for active record imo

grave canopy
#

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.

unkempt narwhal
#

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.

unkempt narwhal
#

Is it still worth migrating from express to NestJS?

grave canopy
tacit mango
astral blaze
#

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

stark pine
#

It is not abandoned but really slow in development

unkempt narwhal
snow ingot
#

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.

snow ingot
stark pine
fervent lily
#

gee why use oracle if not bcuz of legacy

stark pine
#

quod erat demonstrandum

fervent lily
#

still trying to find ppl that use it for other reasons x)

robust berry
shell cedar
# robust berry 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

robust berry
#

Sorry coulnt send the message as it was blocked

shell cedar
#

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

robust berry
#

Does it has virtual column?

shell cedar
#

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

unkempt narwhal
#

Can mikroorm do computed columns?

shell cedar