# count-management-module

> count-management-module is used to manage counter for specific key passed by the user. It also manage past state of counter for all key through database entry.

Latest version **2.0.3** (published 2016-10-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install count-management-module
pnpm add count-management-module
yarn add count-management-module
bun add count-management-module
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2016-10-19 |
| First published | 2016-10-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Chandrakant Thakkar |
| Maintainers | chandrakantthakkardigicorp |
| Keywords | count, management, module |

## Links

- npm: https://www.npmjs.com/package/count-management-module
- Repository: https://github.com/digicorp/count-management-module
- Homepage: https://github.com/digicorp/count-management-module#readme
- Issues: https://github.com/digicorp/count-management-module/issues
- npm.io page: https://npm.io/package/count-management-module

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) *
- [node-database-executor](https://npm.io/package/node-database-executor.md) *
- [node-database-connectors](https://npm.io/package/node-database-connectors.md) *

## Recent versions

- 2.0.3 (latest) — 2016-10-19
- 2.0.2 — 2016-10-18
- 2.0.1 — 2016-10-17
- 2.0.0 — 2016-10-17
- 1.0.6 — 2016-10-17

## README

## count-management-module
#### Author: Chandrakant Thakkar
##### Created on: 14th Oct 2016

---
###### count-management-module is used to manage counter for specific key passed by the user. It also manage past state of counter for all key through database entry.

- To use this module, It requires 'tbl_uniquekey' table into database.'tbl_uniquekey' table defination is as following.

| Field | Type | Key | Default |
| :------------- | :------------- |:------------- |:------------- |
| UK_key | varchar(30) | NO | PRI |
| UK_value | int(11) | YES | - |

- mysql script for table 'tbl_uniquekey'
```javascript
CREATE TABLE `tbl_uniquekey` (
  `UK_key` varchar(30) NOT NULL,
  `UK_value` int(11) DEFAULT NULL,
  PRIMARY KEY (`UK_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

---
#### Function

 * _getUniqueNumber :_

 - _Sample 1_
 ```javascript  
 var generateNextCounter = require('count-management-module');  
 var sendData = {
   "id": "UNIQUEKEY",//id: unique key for which it create unique counter
   "count": 1,//count: update counter value to plus 1 in 'tbl_uniquekey' table at a time
   "dbConfig": sampleConfig
 };
 generateNextCounter.getUniqueNumber(sendData, {}, function(data) {
 var nextCounter=data.content;
 });
 ```



 - _sampleConfig_ : Configuration for database connection. (As given below)
 ```javascript
 var sampleConfig = {
   type: "database",
   engine: 'MyISAM',
   databaseType: 'mysql',
   database: 'database',
   host: "hostname",
   port: "port",
   user: "user",
   password: "password",
   cacheResponse: false
 };
 ```

 - In Sample 1 it creates one entry into table 'tbl_uniquekey' with UK_key as 'UNIQUEKEY' and UK_value as 1 and return 1 value as next counter in 'data.content' variable. while calling same method again it update entry into table 'tbl_uniquekey' for UK_key 'UNIQUEKEY' with UK_value as 2 and return next counter value as 2 in 'data.content' variable.


 - _Sample 2_
 ```javascript  
 var generateNextCounter = require('count-management-module');  
 var sendData = {
   "id": "UNIQUEKEY",//id: unique key for which it create unique counter
   "count": 5,//count: update counter value to plus 5 in 'tbl_uniquekey' table at a time
   "dbConfig": sampleConfig
 };
 generateNextCounter.getUniqueNumber(sendData, {}, function(data) {
   var counterStart=data.content;
   for(i=0;i<5;i++){
    console.log("counter value:"+counterStart);
    counterStart=counterStart+1;
   }
 });
   ```
 - In Sample 2 we require 5 counters at a same time, it creates one entry into table 'tbl_uniquekey' with UK_key as 'UNIQUEKEY' and UK_value as 5 and return 1 value as next counter in 'data.content' variable. now we can generate all five counter for key 'UNIQUEKEY' with starting value as 1 and go till 5 using loop.

 - while calling same method again it update entry into table 'tbl_uniquekey' for UK_key 'UNIQUEKEY' with UK_value as 10 and return next counter value as 6 in 'data.content' variable.now we can generate all five counter for key 'UNIQUEKEY' with starting value as 6 and go till 10 using loop.

---
_Source: https://npm.io/package/count-management-module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
