Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including loopback-increment-mixin with all npm packages installed. Try it out:

var loopbackIncrementMixin = require("loopback-increment-mixin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

loopback-increment-mixin v0.8.2

Loopback Mixin for incrementing any number property in your models

loopback-increment-mixin

Increments number properties of models by a specified number.

NOTE

This mixin currently doesn't work for bulk inserted values, even though it will return an updated count the actual value will be unchanged.

Installation

Run

npm install --save loopback-increment-mixin

Add to ./server/model-config.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../node_modules/loopback-increment-mixin",
      "../common/mixins",
      "./mixins"
    ]
  }
}

Usage

Inside your ./common/models/{modelname}.json insert the following lines:

"mixins": {
  "Increment": {
    "properties": ["count", "count2"]
  }
},

Then when updating a model the value you pass to the count and count2 properties will increase (or decrease - negative numbers also work) the value the server has for count and count2 for that instance.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free