Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quantal-base-model

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quantal-base-model - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

.idea/quantal-base-model.iml

47

lib/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc