Moving from TypeORM to MikroORM #4431
Replies: 14 comments 23 replies
-
@olivermrbl Just a sudden train of thought. Since there is ORM switch, is there any capacity within the team to inject the store_id across all the models ? So moving forward if anyone want to implement multivendor/marketplace can just work on extending the relevant services only. Your team knows best on where the store id would be relevant for the use case. |
Beta Was this translation helpful? Give feedback.
-
Voicing a concern here: Mikro ORM is owned by a single person who owns ~90% of contributions While it is certainly sometimes frustrating to work with, prisma is maintained by dozens actively and hundreds occasionally With extensions such as Prisma-Multischema (which is quite simple and could be forked if the owner of that repo ever goes dark) Your comment suggests that there will be a DAL in the future, do you have any roadmap for that? |
Beta Was this translation helpful? Give feedback.
-
Any update on this? I would strongly recommend going for Prisma, though it's more of a query builder than an ORM. It's very mature and has a large community. I've tried about every JS ORM out there and it's miles ahead of the competition. |
Beta Was this translation helpful? Give feedback.
-
Prisma just dropped support for serverless database: They're working on Cloudflare Worker and Vercel Edge Function support, Medusa team should ask for early access: |
Beta Was this translation helpful? Give feedback.
-
Hi! For those who are suggesting using Prisma, I think Prisma has still some challenges to overcome when it comes to implementing performant SQL |
Beta Was this translation helpful? Give feedback.
-
Nevertheless, it's a great decision. There is a top one problem that one was created by one guy. As you know underbox of the mikro-orm is knex query builder. The knex is awesome. In fact, the mikro-orm supports to do some jobs easier (crud operations, joins, etc.). |
Beta Was this translation helpful? Give feedback.
-
Would rather raw SQL tbh. Migrating ORM is no joke, your application is large and relatively complex, what is the likelihood you'll have to do this again in the future? Especially considering the concerns that other people have brought up: mikro-orm is mostly developed by a single individual. |
Beta Was this translation helpful? Give feedback.
-
We want similar things when choosing a provider. |
Beta Was this translation helpful? Give feedback.
-
I have gone through like 5-6 threads (reddit/github) regarding which is the best ORM. Most of them are saying Prisma is not a good ORM due to the basic things being missed. and it's quite heavy compared to other ORMs like Mikro-orm and Drizzle. So I guess choosing Mikro over primsa would be a good choice. Also for reference, here are the ORMs or query builder I have looked at: PS: I have been using TypeORM for over 4 years now. It's great but not really being updated (just stable) and TS support is not that great. |
Beta Was this translation helpful? Give feedback.
-
Is there any plan to support other databases like MongoDb or MySql? I see that MikroORM does support many database |
Beta Was this translation helpful? Give feedback.
-
What is the current state of this process? How is the isolation of the modules coming along? I'm very anticipated to contribute to the support of different database drivers other than PostgreSQL. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the amazing work you guys are doing, would really love to know if you have any updates on this. |
Beta Was this translation helpful? Give feedback.
-
MikroORM as a project lacks institutional sponsorships. Do you foresee the project being well-maintained despite the lack of proper funding? This is not a question, but I want to understand your perspective and thoughts. |
Beta Was this translation helpful? Give feedback.
-
Hi @olivermrbl , I am also struggling with TypeORM, Trying basic oneToMany and then ManyToOne, it doesn't work while exdending the product entity, Below is my Code. Product.ts Product as MedusaProduct, @entity() @onetomany((type) => AttributeGroup, (attributeGroup) => attributeGroup.product) // AttributeGroup @entity() @column() @column("simple-json") @manytoone(() => Product, (product) => product.attributeGroups) When i call the admin endpoint from postman , It returns below error query: SELECT "product"."id" AS "product_id", "product"."created_at" AS "product_created_at", "product"."updated_at" AS "product_updated_at", "product"."deleted_at" AS "product_deleted_at", "product"."title" AS "product_title", "product"."subtitle" AS "product_subtitle", "product"."description" AS "product_description", "product"."handle" AS "product_handle", "product"."is_giftcard" AS "product_is_giftcard", "product"."status" AS "product_status", "product"."thumbnail" AS "product_thumbnail", "product"."weight" AS "product_weight", "product"."length" AS "product_length", "product"."height" AS "product_height", "product"."width" AS "product_width", "product"."hs_code" AS "product_hs_code", "product"."origin_country" AS "product_origin_country", "product"."mid_code" AS "product_mid_code", "product"."material" AS "product_material", "product"."collection_id" AS "product_collection_id", "product"."type_id" AS "product_type_id", "product"."discountable" AS "product_discountable", "product"."external_id" AS "product_external_id", "product"."metadata" AS "product_metadata", "profiles"."id" AS "profiles_id", "profiles"."created_at" AS "profiles_created_at", "profiles"."updated_at" AS "profiles_updated_at", "profiles"."deleted_at" AS "profiles_deleted_at", "profiles"."name" AS "profiles_name", "profiles"."type" AS "profiles_type", "profiles"."metadata" AS "profiles_metadata", product.attributeGroups FROM "public"."product" "product" LEFT JOIN "public"."product_shipping_profile" "product_profiles" ON "product_profiles"."product_id"="product"."id" LEFT JOIN "public"."shipping_profile" "profiles" ON "profiles"."id"="product_profiles"."profile_id" AND ("profiles"."deleted_at" IS NULL) WHERE ( "product"."id" IN ($1) ) AND ( "product"."deleted_at" IS NULL ) -- PARAMETERS: ["prod_01J2GCYV1H5GCR7X13RFMB8E7C"] |
Beta Was this translation helpful? Give feedback.
-
Hi everyone.
As some of you already know, we started moving toward MikroORM as the default ORM of Medusa.
This post intends to provide an overview of the reasons for the change, why we chose to go with MikroORM, and how our new ORM implementation will differ from the current approach.
Why are we changing ORM?
There are numerous reasons behind our decision to move away from Typeorm, some technically grounded and others relating to maintainability.
Here are three of them:
Lack of responsiveness and maintenance
We have been using Typeorm for nearly three years and have generally been satisfied with what the project has helped us achieve. However, it appears that the core maintainers of the package are becoming less attentive than before. Issues are going unanswered, pull requests are left hanging, and upgrades are breaking without documentation.
The last minor upgrade caused a range of business-critical issues that we reported and offered to help fix. Only a few of these were addressed by the core Typeorm team, even though the issues effectively made Typeorm unsuitable for production use, provided you want to use specific features.
Serverless portability
In April, we introduced the concept of Modules, which are self-contained pieces of code that can run independently from the main core application e.g. in serverless environments or edge functions. Some of these environments come with constraints around bundle size, e.g. the maximum size for a Vercel Edge Functions is 1mb on the Hobby Plan. Thus, going forward, we’ll have to be cautious about our choice of libraries to ensure they never become a limiting factor for the portability of our commerce modules.
The bundle size of Typeorm is very large, because all functionality, database drivers, CLI, utils, etc. are bundled in one package. Therefore, in our quest to make Medusa portable to modern environments, moving away from Typeorm was inevitable.
Timing
It is very rare, you get the opportunity to rethink your ORM and data layer. The modularization of our core is one of those rare occasions, and we are leveraging that opportunity to build a more robust and flexible foundation for the future.
What made us choose MikroORM?
When choosing our next ORM we were split between a lightweight query builder and a fully-fledged ORM. Ultimately, we decided to with the latter to avoid having to build a lot of ORM-type APIs ourselves and because of its familiarity with the core team.
The default ORM in Medusa will be MikroORM](https://mikro-orm.io/).
Our reasoning for going with MikroORM specifically is fairly trivial.
Syntax
MikroORM is syntactically similar to Typeorm, making the migration more seamless for our core team, users, and developer community. See the examples below.
Defining an entity
Using repositories
In addition to having a similar syntax, this project seems to be very actively maintained (with response times of less than a day), and the bundle size is kept small enough to ensure it won’t be an issue for portability to serverless environments.
These three arguments constitute the reason for going with MikroORM.
What will we be doing differently?
In our current implementation, Typeorm is tightly coupled with our repository layer. This means that replacing Typeorm would require a tremendous amount of work, to the extent of being almost impossible.
This tight coupling is somewhat contradicting what we want to offer developers. Developers using Medusa should be equipped with a strong tooling comprising highly customizable and extensible primitives. If your product is better off with a different ORM than what Medusa ships with by default, you should be able to replace this without jumping through hoops.
Introducing a DAL
As we replace Typeorm, we will create a data access layer (DAL), defining a set of generic methods to query data from your chosen data store. The DAL separates the business logic from the ORM. It serves as a contract for what you will – as a minimum – have to implement if you wish to switch out the default ORM or connect to an entirely different type of storage provider. This allows developers to choose the ORM that best fits their needs.
We are excited about the new DAL implementation because of its flexibility and hope to see new use cases of our modules as we open up the underlying data layer.
What will this mean for your setup?
The migration away from Typeorm to MikroORM will happen in parallel with breaking down our entire architecture into modules, that are shipped independently from the core in separate npm packages. This approach will make the migration long-lasting and, hopefully, much less painful for projects that have extended the data layer with custom repositories and schemas.
We are still in the early stages of separating our modules from the core, and there is still a lot of work to be done on our side before you have to think about migrating your customizations. When the time comes, we will provide a thorough walkthrough, taking you through the migration in the most seamless way possible.
Finally...
...as always, we appreciate your feedback and input. Please don’t hesitate to ask questions or voice concerns about our move away from Typeorm. We will address them to the best of our ability.
Beta Was this translation helpful? Give feedback.
All reactions