Hi, I’m having an issue using Prisma with Functions on DigitalOcean’s App Platform. I’ve deployed an app and a function together, and I need to access the Prisma schema and client from the app to the function. I’ve tried multiple approaches, but nothing has worked so far. Is there a solution for this?"
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey Jirapat!
This happens because functions in DigitalOcean’s App Platform are isolated from the web services where your main app and Prisma Client reside. This separation means that your function code doesn’t automatically have access to the Prisma Client or schema defined in your web service. Both are indipendant.
What you’ll need to do is to make sure the Prisma Client is bundled directly with your function’s code and that your database connection is correctly configured.
First, make sure the Prisma Client is installed as a dependency in the function’s own
package.json
. Even though the client might already exist in your main app, functions operate in a separate environment, so they need their own instance.After adding Prisma to your function’s dependencies, generate the Prisma Client within the function’s directory using
npx prisma generate
.You also need to make sure the function has the correct database connection URL. You can do this by setting the
DATABASE_URL
environment variable for the function, either in the App Spec YAML file or through the DigitalOcean Control Panel. This URL should point to your DigitalOcean Managed Database.If deploying the Prisma Client with your function becomes too much due to size or complexity, an alternative approach would be to let your main app handle database interactions. You could create a REST API endpoint in your main app for your function to call when it needs to perform database operations. This way, your function can remain lightweight and offload database work to the web service.
Hope this helps!
- Bobby
This comment has been deleted