# quantal-base-model

> A simple wrapper aroud bookshelf-modelbase

Latest version **0.0.7** (published 2017-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install quantal-base-model
pnpm add quantal-base-model
yarn add quantal-base-model
bun add quantal-base-model
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2017-07-06 |
| First published | 2017-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | quophyie |
| Maintainers | quophyie |
| Keywords | bookshelf, models, bookshelf-model, orm, model |

## Links

- npm: https://www.npmjs.com/package/quantal-base-model
- Repository: https://github.com/quophyie/quantal-base-model
- Homepage: https://github.com/quophyie/quantal-base-model#readme
- Issues: https://github.com/quophyie/quantal-base-model/issues
- npm.io page: https://npm.io/package/quantal-base-model

## Dependencies (2)

- [quantal-errors](https://npm.io/package/quantal-errors.md) 0.0.12
- [bookshelf-modelbase](https://npm.io/package/bookshelf-modelbase.md) ^2.10.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2017-07-06
- 0.0.6 — 2017-06-27
- 0.0.5 — 2017-03-21
- 0.0.4 — 2017-03-21
- 0.0.3 — 2017-03-21
- 0.0.2 — 2017-03-21
- 0.0.1 — 2017-03-17

## README

# Quantal Base Model

A simple wrapper around [bookshelf-modelbase](https://github.com/bsiddiqui/bookshelf-modelbase). Unlike, [bookshelf-modelbase](https://github.com/bsiddiqui/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](https://github.com/quophyie/errors.git). 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**
 ```javascript
 /**
       * Returns a single instance of a model
       * @param filter - the filter to pass fetch
       * @param options {Object} - the options to pass to model.fetch
       * @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned
       * @returns {Promise}
       */
      findOne (filter, options, bConvertResultToJson = true)
```

 **model.create**
```javascript
 /**
       * Naive add - create and save a model based on data
       * @param {Object} data
       * @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.Model)} single Model
       */
      create (data, options, bConvertResultToJson = true)
```

 **model.destroy**
```javascript
      /**
       * Naive destroy
       * @param {Object} options - The bookshelf destroy options
       * @param options.id {Number|String} - The id of the model to be deleted
       * @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned
       * @return {Promise(bookshelf.Model)} empty Model
       */
      destroy (options, bConvertResultToJson = true)
```

 **model.findAll**
```javascript
 /**
       * Naive findAll - fetches all data for `this`
       * @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 (filter, options, bConvertResultToJson = true) 
```

 **model.findWhere**
```javascript
    /**
       * 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)
```

 **model.findById**
```javascript

      /**
       * Find a model based on it's ID
       * @param {String | Number} id The model's ID
       * @param {Object} [options] Options used of model.fetch
       * @param {Boolean} [bConvertResultToJson=true] - if true, result will be converted to JSON, otherwise Bookself model instance will be returned
       * @return {Promise(bookshelf.Model)}
       */
      findById (id, options, bConvertResultToJson = true)
```

 **model.findOrCreate**
```javascript
    /**
       * Find or create - try and find the model, create one if not found
       * @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
       * @return {Promise(bookshelf.Model)} single Model
       */
      findOrCreate (data, options, bConvertResultToJson = true)
```

 **model.update**
```javascript
      /**
       * Naive update - update a model based on data
       * @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
       * @return {Promise(bookshelf.Model)} edited Model
       */
      update (data, options, bConvertResultToJson = true)
```

 **model.upsert**
```javascript
      /**
       * 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 {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, updateData, options, bConvertResultToJson = true)
```

# Licence

    MIT

---
_Source: https://npm.io/package/quantal-base-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
