warehouse.ai-status-models
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "warehouse.ai-status-models", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "models for warehouse.ai-status-api", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,10 +19,29 @@ const Wrap = require('./wrap'); | ||
* @param {String} params.version Version for counter table | ||
* @param {Number} amount Number to increment | ||
* @returns {Promise} when operation complete | ||
* @public | ||
*/ | ||
async increment(params) { | ||
async increment(params, amount = 1) { | ||
const client = await this._getConnection(); | ||
const query = `UPDATE status_counter SET count=count+1 WHERE pkg=:pkg AND env=:env AND version=:version`; | ||
const query = `UPDATE status_counter SET count=count+${amount} WHERE pkg=:pkg AND env=:env AND version=:version`; | ||
return client.execute(query, params, { prepare: true, counter: true }); | ||
} | ||
/** | ||
* Decrement the given counter for this table in the manual way with the | ||
* cassandra driver until we put this into datastar in a proper way | ||
* | ||
* @function increment | ||
* @param {Object} params Parameters for performing increment | ||
* @param {String} params.env Env for Counter table | ||
* @param {String} params.pkg Pkg for Counter table | ||
* @param {String} params.version Version for counter table | ||
* @param {Number} amount Number to increment | ||
* @returns {Promise} when operation complete | ||
* @public | ||
*/ | ||
async decrement(params, amount = 1) { | ||
const client = await this._getConnection(); | ||
const query = `UPDATE status_counter SET count=count-${amount} WHERE pkg=:pkg AND env=:env AND version=:version`; | ||
return client.execute(query, params, { prepare: true, counter: true }); | ||
} | ||
} | ||
@@ -29,0 +48,0 @@ |
@@ -199,3 +199,15 @@ const thenify = require('tinythen'); | ||
}); | ||
it('should decrement counter after increment and validate the changes', async function () { | ||
await StatusCounter.increment(StatusCounterFixture); | ||
const result = await StatusCounter.findOne(StatusCounterFixture); | ||
assume(result.count).equals(1); | ||
await StatusCounter.increment(StatusCounterFixture); | ||
const result1 = await StatusCounter.findOne(StatusCounterFixture); | ||
assume(result1.count).equals(2); | ||
await StatusCounter.decrement(StatusCounterFixture, 2); | ||
const result2 = await StatusCounter.findOne(StatusCounterFixture); | ||
assume(result2.count).equals(0); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22136
578