mirror of
https://github.com/tornadocash/tornado-core.git
synced 2024-11-01 07:45:20 +01:00
39 lines
640 B
JavaScript
39 lines
640 B
JavaScript
|
|
|
|
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; |