Quantal Base Model
A simple wrapper around bookshelf-modelbase. Unlike, bookshelf-modelbase,
quantal-base-model
will return Json objects by default. This behaviour can be controlled by the bConvertResultToJson
variable
which is passed to each method
NOTE
This module wraps the original bookshelf errors with quantal-errors. The reason being that it makes
handling certain errors easier e.g. (Collection.EmptyError
and Model.NotFoundError
are simply coerced to NotFoundError
)
Install
npm install quantal-base-model
API
model.findOne
/** * Returns a single instance of a model * @param filter - the filter to pass fetch * @param options * @param * @returns */
model.create
/** * Naive add - create and save a model based on data * @param * @param * @param * @return {Promise(bookshelf.Model)} single Model */
model.destroy
/** * Naive destroy * @param * @param options.id * @param * @return {Promise(bookshelf.Model)} empty Model */
model.findAll
/** * Naive findAll - fetches all data for `this` * @param * @param * @param * @return {Promise(bookshelf.Collection)} Bookshelf Collection of all Models */
model.findWhere
/** * Naive findWhere - fetches all data for `this`. This method is an alias for findAll * @param * @param * @param * @return {Promise(bookshelf.Collection)} Bookshelf Collection of all Models */
model.findById
/** * Find a model based on it's ID * @param {String | Number} id The model's ID * @param * @param * @return {Promise(bookshelf.Model)} */
model.findOrCreate
/** * Find or create - try and find the model, create one if not found * @param * @param * @param * @return {Promise(bookshelf.Model)} single Model */
model.update
/** * Naive update - update a model based on data * @param * @param * @param * @return {Promise(bookshelf.Model)} edited Model */
model.upsert
/** * Upsert - select a model based on data and update if found, insert if not found * @param * @param * @param * @param * @return {Promise(bookshelf.Model)} edited Model */
Licence
MIT