Package Exports
- bookshelf-modelbase
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bookshelf-modelbase) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ModelBase 
##Why
Bookshelf.js is awesome. However,
we found ourselves extending bookshelf.Model for the same reasons over and
over - parsing and formatting (to and from DB) niceties, adding timestamps, and
validating data on save, for example. Since these are problems you'll likely
have to solve for most use cases of Bookshelf, it made sense to provide a
convenient set of core model features.
Please note
bookshelf-modelbasewill not force you to use it for all your models. If you want to use it for some and not others, nothing bad will happen.bookshelf-modelbaserequires you to pass in an initialized instance of bookshelf, meaning that you can configure bookshelf however you please. Outside of overridingbookshelf.Model, there is nothing you can do to your bookshelf instance that will breakbookshelf-modelbase.
Features
Adds timestamps (
createdAtandupdatedAt)Validate own attributes on save using Joi. You can pass in a validation object as a class attribute when you extend
bookshelf-modelbase- see below for usage.Writes attributes to the db as
snake_case, but exposes them in code ascamelCase.
##Usage
var db = require(knex)(require('./knexfile'));
var bookshelf = require('bookshelf')(db);
// Pass an initialized bookshelf instance
var ModelBase = require('bookshelf-modelbase')(bookshelf);
var User = ModelBase.extend({
}, {
// validation is passed to Joi.object(), so use a raw object
validation: {
firstName: Joi.string()
}
})