Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/json2d/towerdb
resiliently redundant storage stacks
https://github.com/json2d/towerdb
Last synced: 27 days ago
JSON representation
resiliently redundant storage stacks
- Host: GitHub
- URL: https://github.com/json2d/towerdb
- Owner: json2d
- License: mit
- Created: 2018-06-08T17:18:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-10T03:07:53.000Z (over 6 years ago)
- Last Synced: 2024-12-08T04:35:18.210Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🗼 towerdb
[![towerdb](https://img.shields.io/npm/v/towerdb.svg)]()
[![towerdb](https://img.shields.io/node/v/towerdb.svg)]()
[![towerdb](https://img.shields.io/npm/l/towerdb.svg)]()resiliently redundant storage stacks
## Quick Usage
```javascript
const Tower = require('towerdb')//create a tower
const tower = new Tower()//create a store from memory
const table = {}
const tmem = Tower.createStore({
function get(key,options){
return table[key]
},
function set(key,val,options){
table[key] = val
}
})//add store to tower
tower.use(tmem)async function demo() {
await tower.get('hello', {default:'world'}) //=> world
await tower.get('hello') //=> world//default option with sync function
await tower.get('hello:random', {
default: () => `world-${Math.random().toFixed(10) * Math.pow(10,10)}` //dynamic default value
})await tower.get('hello:random') //=> world-0123456789
//default option with a promise bearing function
function fetchWorld() {
return new Promise((resolve,reject) => {
setTimeout(() => resolve('world'), 2000)
})
}await tower.get('hello:promise', {default: fetchWorld }) //=> world (after waiting 2 seconds)
await tower.get('hello:promise') //=> world}
demo()
```