Version: v0.6.1 - Beta.  We welcome contributors & feedback.  THanks!

Database Settings

Databases are configured in settings/app.jcon.

Entries with a file key will point to a sqlite file in data/db.

    app: {
        // ...

    databases: {

        // default sqlite database
        default: {
            file: app.db  // sqlite

        // 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.


To keep passwords outside of your source code (and out of version control), they are stored in an Environment variable.

Each database has its own variable of the upper-case format: THT_DB_PASSWORD_(KEY)

For example, for the database ID salesData, the variable would be THT_DB_PASSWORD_SALESDATA.

Setting an Environment Variable

To permanently set an environment variable for the current user, edit ~/.bash_profile (or ~/.bashrc), and add a line like this:

export THT_DB_PASSWORD_EXAMPLE="mypa@ssw0rd"

Then run source ~/.bash_profile.

Apache Users

Be sure the environment variable is being set for the user account that the web server is being run as.

If you are running Apache (running as a user such as www-data), you may need to set the variable directly in your Apache config using the mod_env module.


See Also