Ghost/core/shared/models/dataProvider.bookshelf.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Provides access to data via the Bookshelf ORM
*/
/*globals module, require, process */
(function () {
"use strict";
2013-05-19 23:17:21 +04:00
var knex = require('./knex_init'),
PostsProvider = require('./dataProvider.bookshelf.posts'),
UsersProvider = require('./dataProvider.bookshelf.users'),
SettingsProvider = require('./dataProvider.bookshelf.settings'),
DataProvider,
instance;
DataProvider = function () {
if (!instance) {
instance = this;
knex.Schema.hasTable('posts').then(null, function () {
// Simple bootstraping of the data model for now.
var migration = require('../data/migration/001');
migration.down().then(function() {
migration.up().then(function () {
console.log('all done....');
});
});
});
}
return instance;
};
DataProvider.prototype.posts = new PostsProvider();
DataProvider.prototype.users = new UsersProvider();
DataProvider.prototype.settings = new SettingsProvider();
module.exports = DataProvider;
}());