Hello, I’m fairly new to Digital Ocean and Managed Databases and I’ve been having some trouble getting things wired up.
I created an App using the App Platform and have a Managed Database and a handful of Functions in it. I am trying to get one of the Functions to write data to the Managed Database and have been unsuccessful so far. Can anyone provide some steps or documentation on this? Specifically, I am confused about what environment variables are available at runtime and how to use them to connect to the databases within my Managed Database.
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.
Sorry to hear you’re having trouble. We have some documentation on managing databases, though it sounds like you may be past that.
With regard to variables, bind variables can be used to inject credentials for connecting to a database. For example, if you have a database resource called “my-db” you could add an environment variable to your app (or a sub component) with the value:
From within your app the environment variable $DB_URL will contain the connection string for your database. Pass that to your DB client of choice and you should be able to read and write.
Want to learn more? Join the DigitalOcean Community!
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Sign up now