What is the process for generating bookshelf Model objects from an existing MySQL database?
The examples on the Bookshelf.js site show several model objects...
var knex = require('knex')({client: 'mysql', connection:
process.env.MYSQL_DATABASE_CONNECTION });
var bookshelf = require('bookshelf')(knex);
var User = bookshelf.Model.extend({
tableName: 'users',
posts: function() {
return this.hasMany(Posts);
}
});
The closest the Knex.js site comes to this is mentioning migrations. However, using their syntax...
$ npm install -g knex
$ npm install knex --save
$ npm install mysql --save
$ knex init
$ knex migrate:make knextest
... only generates one file with empty functions ...
exports.up = function(knex, Promise) {
};
exports.down = function(knex, Promise) {
};
... which makes sense, since knex is NOT the ORM. I guess I ended up here because Bookshelf didn't mention any tools for this.
On a side note, I've checked my knexfile.js
and made sure it has a valid configuration:
development: {
client: 'mysql',
connection: {
host : 'localhost',
user : 'root',
password : 'oogaboogs',
database : 'knexdb'
}
},
Is this not possible? It would really suck to create thousands of Model objects by hand for an existing database.
Thanks, in advance.