Database Configuration in PormG
PormG uses a simple YAML-based configuration system to manage connections to your PostgreSQL databases. Each database connection is defined in a connection.yml
file inside a dedicated folder (e.g., db
, db_2
).
How Configuration Works
- By default, PormG looks for a folder named
db
containing aconnection.yml
file. - You can use any folder name (e.g.,
db_2
) to manage multiple databases. Each folder should have its ownconnection.yml
and models file.
Creating a Configuration
To set up a new database connection:
- Create a Folder
- Example:
db_2
- Example:
- Run the Configuration Loader
- If the configuration file does not exist, PormG will create a template for you:
PormG.Configuration.load("db_2")
- If
db_2/connection.yml
does not exist, a template will be generated. Edit this file with your PostgreSQL connection details.
- If the configuration file does not exist, PormG will create a template for you:
- Edit the Configuration File
- Open
db_2/connection.yml
and fill in your database host, port, user, password, and database name.
- Open
- Create the Database
- Make sure the database exists in PostgreSQL before loading the configuration.
- Load the Configuration
- Run the loader again to connect:
PormG.Configuration.load("db_2")
- If no error is triggered, the configuration was loaded successfully.
- Run the loader again to connect:
Example: Configuration Script
using Pkg
Pkg.activate(".")
using PormG
PormG.Configuration.load("db_2")
Notes
- You can manage as many databases as you want by using different folders and configuration files.
- The folder will also contain your models and migration files for that database.
- If you try to load a configuration that does not exist, PormG will help you by creating a template.
For more details, see the PormG Documentation or the example scripts in the test/pg/
folder.