npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@c8/base-model

v4.0.0

Published

A base model for all bookshelf-based models on our database layer.

Readme

base-model

A base model for all bookshelf-based models on our database layer.

What it does

  • Adds 'createdDate' and 'lastUpdatedDate' timestamps to the Model (this can be changed by setting hasTimestamps to false);
  • Adds an 'isDeleted' column for setting the entry as removed, instead of hard-deleting it (this can be changed by setting delAttribute);
  • Provides CRUD methods (findAll, findById, insert, removeById, updateById);
    • Returns plain javascript objects and exceptions, which creates a clear separation between bookshelf and your business logic code;
    • 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'

Install

npm install @c8/base-model

Usage

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)

API

findAll(opts)

  • Gets all entries from the database.
  • @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)

  • Gets an entry object by it's ID.
  • @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)

  • Gets all entries that match the given criteria
  • @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)

  • Creates a new entry.
  • @param {object} obj - The object to be created.
  • @returns {Promise.<Object>} A Promise resolving to the newly created entry.

removeById(id)

  • Removes the given entry from the database.
  • @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)

  • Updates an existing entry in the database.
  • @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.