Database Configuration
Databases are configured in your app config file for your local environment.
By default, THT will look in config/app.local.jcon
.
Entries with a file
key will point to a sqlite file in data/db
.
{ app: { ... } databases: { // default sqlite database default: { driver: sqlite file: app.db } // exampe of a mysql database another: { driver: mysql // or 'pgsql' server: localhost database: example username: dbuser // Password set in Environment variable: // 'THT_DB_PASSWORD_ANOTHER' } } }
All functions use the default
database. To point to another database, call Db.use
(see below).
THT will automatically connect to each database as needed, and disconnect when the current request ends.
NOTEDatabase operations are not callable within templates, in order to keep your View code separate from your app logic.