Hi Now I am implementing prisma middleware. What ...
# orm-help
s
Hi Now I am implementing prisma middleware. What I want to do by using middleware is to execute SET app.currentTenant='xxxxxx' with every SQL execution to realize tenant isolation of Saas. So my middleware is like this:
Copy code
this.$use(async (params, next) => {
      if ( xxxxxxx === yyyyyy ) {
        await this.$executeRaw(`SET app.currentTenant='${tenantId}';`);
      }
      return next(params);
    });
So I want to confirm that in this case the connection of both executeRaw and next is same or not? Or is this any good way to do this?
r
@Sunao Suzuki 👋 We don’t have native support for this yet, but there’s a workaround that you can check here in the feature request 🙂
s
@Ryan Thank you so much but I want to get the answer of this.
So I want to confirm that in this case the connection of both executeRaw and next is same or not?
r
It should be as people are using the middleware workaround.
s
@Ryan is there way to use same DB connection for queries in both
$executeRaw
and
next(param)
in my code? Or is it natively supported?
r
Probably @Joël has an idea 🙂
j
I would say that with a transaction you will have a guarantee, not sure here
👍 1