Grind’s Database provider integrates Grind with knex.js.
First, add the grind-db
package via your preferred package manager:
yarn add grind-db
Next, you’ll need to add DatabaseProvider
to your app providers in app/Boostrap.js
:
const app =appproviders
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:
yarn add mysql2yarn add mariasqlyarn add sqlite3yarn add pg
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.
app
Your database config should live in /config/database.json
.
Here’s an example of a config file that supports both MariaDB and SQLite:
The default
key tells the Database provider which connection it should load by default.