Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@c8/base-model
Advanced tools
Readme
A base model for all bookshelf-based models on our database layer.
'createdDate'
and 'lastUpdatedDate'
timestamps to the Model (this can be changed by setting hasTimestamps
to false
);delAttribute
);findAll
, findById
, insert
, removeById
, updateById
);
remove
does not hard-delete, instead it sets the is_deleted
column to true
(this behaviour can be changed by
overriding the function or by setting delAttribute
to false);NOTE: BaseMode assumes you're using the awesome bookshelf-camelcase
plugin. If you're not, just set hasTimestamps: ['created_date', 'last_updated_date']
and delAttribute: 'is_deleted'
npm install @c8/base-model
BaseModel
requires you to pass in an initialized instance of bookshelf, like in the example below:
const bookshelf = require('bookshelf')(db)
const BaseModel = require('../lib/index')(bookshelf)
const MyModel = BaseModel.extend({
tableName: 'my_table' // needs to have created_date, last_updated_date and is_deleted columns
})
module.exports = bookshelf.model('MyModel', MyModel)
findAll(opts)
@param {object} [opts]
An optional options object@param {boolean} [opts.includeRemoved]
Find removed items as well@returns {Promise.<Array>}
A Promise resolving to the fetched entries array.findById(id, opts)
@param {number} id
- The ID of the entry to get.@param {object} [opts]
An optional options object@param {boolean} [opts.includeRemoved]
Find removed items as well@returns {Promise.<Object>}
A promise resolving to the fetched entry.@throws {NotFoundError}
An entry with the given id
must exist.findWhere(where, opts)
@param {number} where
- The criteria to be met.@param {object} [opts]
- An optional options object.@param {boolean} [opts.includeRemoved]
- Find removed items as well.@returns {Promise.<Array>}
- A promise resolving to the fetched entries array.insert(obj)
@param {object} obj
- The object to be created.@returns {Promise.<Object>}
A Promise resolving to the newly created entry.removeById(id)
@param {number} id
- The entry ID.@returns {Promise.<Object>}
A Promise resolving to the destroyed entry.@throws {NotFoundError}
A Campaign with the given id
must exist.updateById(id, entry, opts)
@param {number} id
- The ID of the Campaign to update.@param {object} entry
- The Campaign object to update.@param {object} [opts]
An optional options object@param {boolean} [opts.includeRemoved]
Find removed items as well@returns {Promise.<Object>}
A Promise resolving to the updated entry fields.@throws {TypeError}
entry.id
must exist and be integer.@throws {NotFoundError}
An entry with the given entry.id
must exist.FAQs
A base model for all bookshelf-based models on our database layer.
The npm package @c8/base-model receives a total of 18 weekly downloads. As such, @c8/base-model popularity was classified as not popular.
We found that @c8/base-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.