MikroORM with Sapphire (AsyncLocalStorage)
Is there a good way of creating AsyncLocalStorage contexts when working with sapphire? This is used for forking the EntityManager instance in MikroORM but I can find some other use-cases for it as well.
My first idea is rather messy and I'm not sure if it even works: I would monkey patch all loaded pieces and wrap their run() methods with a function that would create the context.
Is there a better way to do this?
4 Replies
Another idea I've seen by searching this server (old message from 2022), is to use a method decorator, but I think I would like the context to be automatically created without explicit decorators.
should note that most people use Prisma as ORM here. I cant help you with this either as I dont use MikroORM.
yeah I got that feeling, I want to switch from prisma to MikroORM. I have mixed feelings about prisma and wanted to try something new
As a side note, if you want to switch from Prisma to something similar, there’s DrizzleORM
But as for MikroORM’s stuff… not the first question about it that’s been opened, I don’t know what they’re doing but it’s starting to feel like users use it in a way that works around using MikroORM rather than with them, and I’m curious to see more details about it to see what mechanisms we can recommend to make sure of everything