-
Notifications
You must be signed in to change notification settings - Fork 13
Database
Through SQLAlchemy, Grace supports SQLite, MySQL/MariaDB, PostgreSQL, Oracle and Microsoft SQL Server (Supported dialects). The configurations are divided in three sections. production, development and test. They can use the same or completely different databases, dialects, hosts, etc.
By default, Grace will generate the database configuration with SQLite configured for development and testing. Production, on the other hand, expects to receive a database URL defined by an environment variable named DATABASE_URL
.
To set up the connection to your database, update or create config/database.cfg
. You can have up to three database configurations, one for each environment (production, test and development). Each section is delimited by [database.<environment>]
For example, the production section would be [database.production]
.
Value | Description | Used by (* means used by all) |
---|---|---|
adapter | SQL dialect+driver (driver optional) | * |
user | User name | MySQL, PostgreSQL, Oracle, Microsoft SQL Server |
password | User password | MySQL, PostgreSQL, Oracle, Microsoft SQL Server |
host | Database server’s hostname | MySQL, PostgreSQL, Oracle, Microsoft SQL Server |
port | Database server’s port | MySQL, PostgreSQL, Oracle, Microsoft SQL Server |
database | Database name | * |
url | Complete database URL | |
(Bypass configurations) | * |
Below you will find a few example using the most common databases dialects. All examples are under the development section but can be applied to other environment sections.
[database.development]
adapter = sqlite
database = grace_development.db
[database.development]
adapter = mysql
host = localhost
port = 3306
database = grace_development
user = grace
password = GraceHopper1234
[database.development]
adapter = postgresql
host = localhost
port = 5432
database = grace_development
user = grace
password = GraceHopper1234
Environment variables can be used to dynamically populate the configuration files. Every values surrounded by ${}
will be inserted into the configuration on execution.
Consider an environment variable named DATABASE_URL
containing sqlite:///grace_development.db
[database.development]
url = ${DATABASE_URL}
Will be read as
[database.development]
url = sqlite:///grace_development.db