(c) 2013 Tim Griesser
Bookshelf may be freely distributed under the MIT license.
For all details and documentation:
http://bookshelfjs.org
All external libraries needed in this scope.
All local dependencies... These are the main objects that need to be augmented in the constructor to work properly.
Finally, the Events
, which we've supplemented with a triggerThen
method to allow for asynchronous event handling via promises. We also
mix this into the prototypes of the main objects in the library.
Constructor for a new Bookshelf
object, it accepts
an active knex
instance and initializes the appropriate
Model
and Collection
constructors for use in the current instance.
Allows you to construct the library with either Bookshelf(opts)
or new Bookshelf(opts)
.
If the knex isn't a Knex
instance, we'll assume it's
a compatible config object and pass it through to create a new instance.
The Model
constructor is referenced as a property on the Bookshelf
instance,
mixing in the correct builder
method, as well as the relation
method,
passing in the correct Model
& Collection
constructors for later reference.
Shortcut for creating a new collection with the current collection.
The collection also references the correct Model
, specified above, for creating
new Model
instances in the collection. We also extend with the correct builder /
knex
combo.
Used internally, the Relation
helps in simplifying the relationship building,
centralizing all logic dealing with type & option handling.
Grab a reference to the knex
instance passed (or created) in this constructor,
for convenience.
A Bookshelf
instance may be used as a top-level pub-sub bus, as it mixes in the
Events
object. It also contains the version number, and a Transaction
method
referencing the correct version of knex
passed into the object.
Keep in sync with package.json
.
Helper method to wrap a series of Bookshelf actions in a knex
transaction block;
Provides a nice, tested, standardized way of adding plugins to a Bookshelf
instance,
injecting the current instance into the plugin, which should be a module.exports.
Alias to new Bookshelf(opts)
.
The forge
function properly instantiates a new Model or Collection
without needing the new
operator... to make object creation cleaner
and more chainable.
Finally, export Bookshelf
to the world.
Bookshelf.js 0.6.11