pooling.js v3.0.3
Pooling.js
Introduction
Handle statuses of data, and store the information in a Keyv database
Examples
Creates a item and gets its value
const Pool = require('pooling.js');
const pool = new Pool();
pool.set('cooldataofthisitem', 'coolstatus')
.then(item => {
return pool.get(item.key);
})
.then((data) => {
console.log(data)
// cooldataofthisitem
});
Documentation
Classes
Item
A item instance used to interact with pool items
Kind: global class
- Item
- new Item(pool, key, status)
- .set(value) ⇒ Promise.<true>
- .setStatus(status) ⇒ Promise.<Item>
- .get() ⇒ Promise.<any>
new Item(pool, key, status)
Param | Type | Description |
---|---|---|
pool | Pool | The pool class |
key | string | The key name of the item |
status | string | Status name the item belongs to |
item.set(value) ⇒ Promise.<true>
Sets the value of the item
Kind: instance method of Item
Returns: Promise.<true> - Returns promise, resolves to true if succesfull
Param | Type |
---|---|
value | any |
item.setStatus(status) ⇒ Promise.<Item>
Set the status of the
Kind: instance method of Item
Returns: Promise.<Item> - Promise resolving with the new item
Param | Type |
---|---|
status | string |
item.get() ⇒ Promise.<any>
Gets the value of the item
Kind: instance method of Item
Returns: Promise.<any> - Promise with the value
Pool
Handles database and pools
Kind: global class
- Pool
- new Pool(database)
- .add(value, status) ⇒ Promise.<Item>
- .set(key, value) ⇒ Promise.<true>
- .setStatus(key, status) ⇒ Promise.<Item>
- .get(key) ⇒ Promise.<any>
- .getItemsOf(status) ⇒ Promise.<Array.<Item>>
- .getOf(status) ⇒ Promise.<Array.<any>>
new Pool(database)
Param | Type | Description |
---|---|---|
database | Keyv | The keyv database of choice |
pool.add(value, status) ⇒ Promise.<Item>
Add a item to the pool
Kind: instance method of Pool
Returns: Promise.<Item> - Promise with item
Param | Type |
---|---|
value | Item | Any |
status | string |
pool.set(key, value) ⇒ Promise.<true>
Sets a value of a key
Kind: instance method of Pool
Returns: Promise.<true> - promise with true if succesfull
Param | Type |
---|---|
key | Item | string |
value | any |
pool.setStatus(key, status) ⇒ Promise.<Item>
Sets status of a item
Kind: instance method of Pool
Returns: Promise.<Item> - Promise with the new item
Param | Type |
---|---|
key | Item | string |
status | string |
pool.get(key) ⇒ Promise.<any>
Get item's value
Kind: instance method of Pool
Returns: Promise.<any> - The value
Param | Type |
---|---|
key | Item | string |
pool.getItemsOf(status) ⇒ Promise.<Array.<Item>>
Get all the items with certain status
Kind: instance method of Pool
Returns: Promise.<Array.<Item>> - Array with items
Param | Type |
---|---|
status | string |
pool.getOf(status) ⇒ Promise.<Array.<any>>
get all of the value's with certain status
Kind: instance method of Pool
Returns: Promise.<Array.<any>> - Array with all the values
Param | Type |
---|---|
status | string |