When running Prisma Client in Cloudflare Workers, it must be instantiated inside the handler:
- that's where the DB URL env var is available which is needed to instantiate the driver adapter
- I/O objects can't be shared across Worker instances
This is different compared to the recommendation typically given for using Prisma Client in Serverless environments where it's supported to be instantiated outside the handler.
Instantiating Prisma Client outside the handler enables reuse of the instance across different function invocations. This also helps prevent the warning: warn(prisma-client) This is the 10th instance of Prisma Client being started.
Since in CF workers, instantiating inside the handler is the only option, the warning is unavoidable and should be removed.