mirror of
https://github.com/tornadocash/tornado-cli.git
synced 2025-06-16 18:49:50 -04:00
init
This commit is contained in:
commit
2e4d59aed0
15 changed files with 703783 additions and 0 deletions
lib
39
lib/Storage.js
Normal file
39
lib/Storage.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
|
||||
class JsStorage {
|
||||
constructor() {
|
||||
this.db = {}
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.db[key]
|
||||
}
|
||||
|
||||
get_or_element(key, defaultElement) {
|
||||
const element = this.db[key]
|
||||
if (element === undefined) {
|
||||
return defaultElement
|
||||
} else {
|
||||
return element
|
||||
}
|
||||
}
|
||||
|
||||
put(key, value) {
|
||||
if (key === undefined || value === undefined) {
|
||||
throw Error('key or value is undefined')
|
||||
}
|
||||
this.db[key] = value
|
||||
}
|
||||
|
||||
del(key) {
|
||||
delete this.db[key]
|
||||
}
|
||||
|
||||
put_batch(key_values) {
|
||||
key_values.forEach(element => {
|
||||
this.db[element.key] = element.value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsStorage
|
Loading…
Add table
Add a link
Reference in a new issue