Hey,
I would like the same db connections to be used for my migrations and my queries. But I cant find in documentation how to point knex at knexfile.js outside of migration environment.
Is there a way to point knex at knexfile.js instead of specifying the same db connection in both knexfile and require('knex') statement? It feels broken to have to do it in both places.
Probably me just missing something in the docs -.-
Thanks,
-Michal
// database.js
'use strict';
var knex = require('knex')(require('./knexfile')[process.env.NODE_ENV]), // Selects the correct DB config object for the current environment
bookshelf = require('bookshelf')(knex);
module.exports = bookshelf;
something like this?
How to Structure Bookshelf.js Models
Yeah I can do that but its not without its own problems ... I feel somewhat uneasy hard coding this special filename in my application. Since knexfile has a special meaning to knex I was hoping there is a way to suggest to knex to use its own configuration file. (the clean way to do it would seem to have knex use knexfile if no custom configuration is given.)
well, knex is what's used underneath bookshelf, and that's passing the knexfile to knex, then just injecting knex's settings into bookshelf, not sure how to make it better, seems ok to me.
Most helpful comment
something like this?
How to Structure Bookshelf.js Models