quantal-base-model
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -8,2 +8,3 @@ 'use strict' | ||
* @param {Object} bookshelf - An initialised instance of bookshelf | ||
* @param {Object} params - The params that are passed to bookshelf | ||
* @param {Object} [validations] - An object of Joi validations | ||
@@ -13,7 +14,7 @@ * @returns {*} | ||
*/ | ||
const BaseModel = (bookshelf, validations) => { | ||
const BaseModel = (bookshelf, params, validations) => { | ||
if (!bookshelf) { | ||
throw new CommonErrors.IllegalArgumentError('An initialised instance of bookshelf is required') | ||
} | ||
const ModelBase = require('bookshelf-modelbase')(bookshelf) | ||
const ModelBase = require('bookshelf-modelbase')(bookshelf, params) | ||
bookshelf.plugin(require('bookshelf-modelbase').pluggable) | ||
@@ -28,3 +29,3 @@ | ||
* Returns a single instance of a model | ||
* @param data - the data to pass fetch | ||
* @param filter - the filter to pass fetch | ||
* @param options {Object} - the options to pass to model.fetch | ||
@@ -34,3 +35,3 @@ * @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
*/ | ||
findOne (data, options, bConvertResultToJson = true) { | ||
findOne (filter, options, bConvertResultToJson = true) { | ||
return bookshelf.Model.prototype.constructor.findOne.apply(this, arguments) | ||
@@ -68,3 +69,3 @@ .then(model => { | ||
* Naive destroy | ||
* @param {Object} options | ||
* @param {Object} options - The bookshelf destroy options | ||
* @param options.id {Number|String} - The id of the model to be deleted | ||
@@ -82,3 +83,3 @@ * @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
.catch(bookshelf.NotFoundError, () => Promise.reject(new CommonErrors.NotFoundError('NotFoundError'))) | ||
.catch(bookshelf.EmptyError, () => Promise.reject(new CommonErrors.NotFoundError('NotFoundError'))) | ||
.catch(bookshelf.NoRowsDeletedError, () => Promise.reject(new CommonErrors.NoRowsDeletedError('NoRowsDeletedError'))) | ||
.catch(err => Promise.reject(CommonErrors.utils.bookshelfToApp(err))) | ||
@@ -89,7 +90,8 @@ }, | ||
* Naive findAll - fetches all data for `this` | ||
* @param {Object} options (optional) | ||
* @param {Object} filter - The filter/ query that will be applied to the find all query | ||
* @param {Object} [options] - The bookshelf destroy options | ||
* @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
* @return {Promise(bookshelf.Collection)} Bookshelf Collection of all Models | ||
*/ | ||
findAll (options, bConvertResultToJson = true) { | ||
findAll (filter, options, bConvertResultToJson = true) { | ||
return bookshelf.Model.prototype.constructor.findAll.apply(this, arguments) | ||
@@ -107,2 +109,13 @@ .then(model => { | ||
/** | ||
* Naive findWhere - fetches all data for `this`. This method is an alias for findAll | ||
* @param {Object} filter - The filter/ query that will be applied to the find all query | ||
* @param {Object} options (optional) | ||
* @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
* @return {Promise(bookshelf.Collection)} Bookshelf Collection of all Models | ||
*/ | ||
findWhere (filter, options, bConvertResultToJson = true) { | ||
return this.findAll(filter, options, bConvertResultToJson) | ||
}, | ||
/** | ||
* Find a model based on it's ID | ||
@@ -128,4 +141,4 @@ * @param {String | Number} id The model's ID | ||
* Find or create - try and find the model, create one if not found | ||
* @param {Object} data | ||
* @param {Object} options | ||
* @param {Object} data - The data to use to find a model. If The model does not exist, this data will be persisted | ||
* @param {Object} options - The options thar are passed to fetch and create | ||
* @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
@@ -148,4 +161,4 @@ * @return {Promise(bookshelf.Model)} single Model | ||
* Naive update - update a model based on data | ||
* @param {Object} data | ||
* @param {Object} options | ||
* @param {Object} data - The data to be used to update a model | ||
* @param {Object} options - The options to pass to save | ||
* @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
@@ -163,2 +176,3 @@ * @return {Promise(bookshelf.Model)} edited Model | ||
.catch(bookshelf.EmptyError, () => Promise.reject(new CommonErrors.NotFoundError('NotFoundError'))) | ||
.catch(bookshelf.NoRowsUpdatedError, () => Promise.reject(new CommonErrors.NoRowsUpdatedError('NoRowsUpdatedError'))) | ||
.catch(err => Promise.reject(CommonErrors.utils.bookshelfToApp(err))) | ||
@@ -169,9 +183,9 @@ }, | ||
* Upsert - select a model based on data and update if found, insert if not found | ||
* @param {Object} selectData Data for select | ||
* @param {Object} updateData Data for update | ||
* @param {Object} [options] Options for model.save | ||
* @param {Object} selectData - Data for select | ||
* @param {Object} updateData - Data for update | ||
* @param {Object} [options] options - for model.save | ||
* @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned | ||
* @return {Promise(bookshelf.Model)} edited Model | ||
*/ | ||
upsert (selectData, options, bConvertResultToJson = true) { | ||
upsert (selectData, updateData, options, bConvertResultToJson = true) { | ||
return bookshelf.Model.prototype.constructor.upsert.apply(this, arguments) | ||
@@ -185,2 +199,3 @@ .then(model => { | ||
.catch(bookshelf.EmptyError, () => Promise.reject(new CommonErrors.NotFoundError('NotFoundError'))) | ||
.catch(bookshelf.NoRowsUpdatedError, () => Promise.reject(new CommonErrors.NoRowsUpdatedError('NoRowsUpdatedError'))) | ||
.catch(err => Promise.reject(CommonErrors.utils.bookshelfToApp(err))) | ||
@@ -187,0 +202,0 @@ } |
{ | ||
"name": "quantal-base-model", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
"bookshelf-modelbase": "^2.10.3", | ||
"quantal-errors": "^0.0.4" | ||
"quantal-errors": "^0.0.5" | ||
}, | ||
@@ -19,3 +19,27 @@ "devDependencies": { | ||
"standard": "^9.0.1" | ||
} | ||
}, | ||
"description": "A simple wrapper aroud bookshelf-modelbase", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/quophyie/quantal-base-model.git" | ||
}, | ||
"keywords": [ | ||
"bookshelf", | ||
"models", | ||
"bookshelf-model", | ||
"orm", | ||
"model" | ||
], | ||
"author": "quophyie", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/quophyie/quantal-base-model/issues" | ||
}, | ||
"homepage": "https://github.com/quophyie/quantal-base-model#readme" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
13
0
182
1
1
1
130
0
45064
+ Addedquantal-errors@0.0.5(transitive)
- Removedquantal-errors@0.0.4(transitive)
Updatedquantal-errors@^0.0.5