Investigate TypeORM Replacement #2363
Replies: 9 comments
-
Very interesting comparison of ORM technologies available for Typescript can be found here. I believe most important things for us at the moment are:
From this list it seems we should evaluate MikroORM and Prisma as both have strong type safety. Ease of migrationFor both ORMs we need to consider seeds we have defined at SQL migrations level. Prisma generates an .sql file so that means we must move typescript logic into SQL language, which might be time consuming. MikroORM has an almost identical approach to migration files as TypeORM so we could just copy paste the content of our existing migrations into newly generated initial migration. PrismaPrisma describes migrating incrementally from TypeORM here, in short there is a tool for introspecting the existing DB schema and generating a language agnostic model file from it. It also updates a metadata table in the DB so that prisma schema considers this DB introspection as an already applied migration. Prisma will autogenerate all types based on the language agnostic model file which means that our code is now only responsible for defining the DTOs, TypeORM model files should be removed. MikroORMTo define entities MikroORM uses decorators the same way as TypeORM, which means that to fully switch we need to rewite all those decorators. on existing models. Initial migration can then be generated from those newly decorated models. There are no utils to not apply initial migration we must manually tweak migrations metadata table as if it was already applied. To switch incrementally we probably need to maintain two ORMs at the same time. Performance[TODO] It's hard to find any comparison between those two and TypeORM Type safetyBoth ORMs support a very interesting feature: if a nested relation has not been explicitly joined during the query a compiler will throw an error if someone tries to access it later, in other words typing is relation loading aware, which might save us some debugging time. A nice thing about Prisma client is that it seems there is only one complete interface for querying data (TypeORM repository like). No need to user query builder when repository does not support something. Raw querying is also supported. MikroORM exposes both a repository and a query builder. PrismaQuote from the linked comparison:
MikroORMBoth inserting and fetching guarantees strong type safety for base model and nested relations, details here. IssuesPrismaMikroORM
|
Beta Was this translation helpful? Give feedback.
-
Following this. |
Beta Was this translation helpful? Give feedback.
-
in addition to what @pbn4 said: nest does support both of them: for prisma it seems like to do pagination & count we would do something similar to what was suggested: prisma/prisma#3087 with https://www.prisma.io/docs/concepts/components/prisma-client/pagination explaining pagination in prisma for mikroorm It seems like either one of these could cover our use case, I do have a bit of a bias towards Prisma, as it seems to have more usage |
Beta Was this translation helpful? Give feedback.
-
I don't particularly have skin in this game, but I've noticed a lot of JS/TS frameworks in general seem to be rallying around Prisma, so I sort of expect that even if it's missing certain features here or there, those gaps will be paved over in time as users of those frameworks will likely be bumping up against similar issues. |
Beta Was this translation helpful? Give feedback.
-
From my initial benchmarks it seems that a fully joined listings query takes 1/6th of the time it takes with TypeORM, which is a significant improvement but it still is an average of 300ms per request over 100 requests, which means that we simply have a lot of joins and paginating listings endpoint was a very good idea. :) |
Beta Was this translation helpful? Give feedback.
-
Some notes on the migrations from TypeORM to prisma:
|
Beta Was this translation helpful? Give feedback.
-
Heads up - validations with Prisma are a do-it-yourself concern. Wherever you are creating or updating models, you have to run validations yourself, outside of the DB ones. For example, these validations:
This has been my biggest gripe with Prisma atm. Someone will forget and not add validation (in our case, we didnt lowercase emails). Ideally, you create wrapper functions around the Prisma operations. |
Beta Was this translation helpful? Give feedback.
-
@seanmalbert Right now after running sole
If those were moved to seeding completely we could rely only on the migration generated by prisma and prisma.schema file. |
Beta Was this translation helpful? Give feedback.
-
@seanmalbert Since
I think to move in Prisma direction we should think about making Listings more loosely coupled to other models and then proceed with migrating. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions