In order to actually use a database, you’ll first need to install the database driver(s) you need. Knex supports a variety of different drivers:
npm install mysql2 --savenpm install mariasql --savenpm install sqlite3 --savenpm install pg --save
The default database connection is exposed via
app.db. For full details on how the query builder works, head over to the knex.js documentation.
Your database config should live in
Here’s an example of a config file that supports both MariaDB and SQLite:
default key tells the Database provider which connection it should load by default.