Databases
Most modern day applications require a database to store structure persistent data. At Customary, we support Postgres databases, which are reliable, scalable, and easy to use. This guide will show you how to create a database on Customary and connect to it from your application.
Creating a Database
To create a database, you need to provide a name, choose a Postgres version, and specify the amount of storage it has. Once created, Customary automatically injects the database’s URL, username, and password into your environment. This allows your application to connect to the database without any manual configuration.
Connecting to the Database
If you’re using Django, you can access these environment variables in your settings.py
file. Here’s an example:
For a vanilla Python application, you can use the psycopg2
library to connect to the database. Here’s an example:
If you’re using Node.js, you can use the pg
library to connect to the database. Here’s an example:
Accessing the Database from the outside
Sometimes, you may need to access your database from somewhere other than your deployment. For security reasons, this is disabled by default. However, you can enable it by setting the “Allow global access” setting on your database. This will open your database to the internet, where you can connect to it using the provided URL, username, and password.
Conclusion
With Customary, managing databases for your deployments is straightforward and pragmatic. You can focus on building your application while we handle the database setup and connection details for you.