eoin-obrien / prisma-extension-kysely

Drop down to raw SQL in Prisma without sacrificing type safety!
https://www.npmjs.com/package/prisma-extension-kysely
MIT License
201 stars 5 forks source link

Transaction closes after running prisma query #89

Closed gautammmanek closed 6 months ago

gautammmanek commented 6 months ago

Not too sure what's going on here, but it seems that the transaction closes when running a prisma query sequentially with using prisma's transaction client for kysely. For example:

return await prisma.$transaction(async (tx) => {
          const { teamId } = await tx.inventory.findFirstOrThrow({
            where: {
              id: inventoryId,
            },
            select: { teamId: true },
          })
         // throws an error saying the transaction has closed
         const ambulancesInTeam = await tx.$kysely
            .selectFrom('Inventory')
            .leftJoin('Team', 'Team.id', 'Inventory.teamId')
            ...
})

Specifically, the following error specifies that the queryRaw invocation by kysely is performed on a closed transaction:

TRPCClientError: 
Invalid `prisma.$queryRawUnsafe()` invocation:
Transaction API error: Transaction already closed: A query cannot be executed on a committed transaction.
    at TRPCClientError.from (webpack-internal:///./node_modules/@trpc/client/dist/TRPCClientError-38f9a32a.mjs:33:20)
    at eval (webpack-internal:///./node_modules/@trpc/client/dist/links/httpLink.mjs:45:105)