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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bookshelf-committed-plugin

v2.0.1

Published

A plugin for Bookshelf ORM to fire the `committed` event when a model is `saved` inside a transaction and after the transaction has successfully committed

Downloads

5

Readme

bookshelf-committed-plugin

npm install bookshelf-committed-plugin

A plugin for Bookshelf ORM to fire the committed event on saved and transaction completed successfully.

saved: insert or update

Use case

The bookshelf created, saved, updated events actually fire before the transaction completes. So if you're using a transaction, and you try to load the model or related models in the on handler, the models wont be loaded.

Example and definition

initialize(){
  this.on('committed', (model, attrs, options, previousAttributes) => {
    // do something
  });
}
model: Bookshelf.Model,
attrs: Object, // plain object of attributes that will be updated
options: Object, // options passed to save, including method which is automatically added if not originally in save options
previousAttributes: Object, // plain object of attributes prior to this save, (not neccessarily the same as prior to the transaction)
Bookshelf.plugin(require('bookshelf-committed-plugin'));

FAQ

  • If I do a save on a model twice in the same transaction, will committed event be fired twice? Yes

  • Why did you include previousAttributes when bookshelf supports this via model.previousAttributes() and other bookshelf event handlers don't have this parameter? Bookshelf's previousAttributes() is unreliable because its conceivable that the value gets overwritten by another save, before we retrieve the value in the on handler of the other save. Additionally with the case of multiple saves on the same model in the same transaction, the first previousAttributes will be overwritten by the time the committed events get called. Additionally it makes more sense to me to call the event handler with this value as an additional argument rather than storing it in the model itself, as its only relevant immediately post save.