odd-storage
v0.6.0
Published
node.js and browser storage
Downloads
32
Maintainers
Readme
odd-storage
odd-storage is JavaScript library that has two interfaces (sql and sync) for store data in node.js and browsers.
Example
import oddStorage from 'odd-storage'
let storage = new oddStorage.LocalStorage({prefix: '...'})
$('#change-balance-btn').click(() => {
storage.withLock(async () => {
let user = $('#change-balance-user')
let value = parseInt($('#change-balance-value').val(), 10)
$('#change-balance-value').val('')
let isAllow = await request(..., {value: value})
if (!isAllow) {
return setTimeout(() => {
alert(`Action forbidden for user: ${user}, value: ${value}`)
}, 0)
}
let balance = await storage.get(user)
let newBalance = (balance === null ? 0 : balance) + value
await storage.set(user, newBalance)
setTimeout(() => {
alert(`Balance changed for user: ${user}, new balance: ${balance}`)
}, 0)
})
})
API
- Abstract
- Mixes
- ready-mixin
- Methods
- Inheritance
- Mixes
- AbstractSQL
- Methods
- Inheritance
- AbstractSync
Abstract
open
Open storage and set ready state for current instance.
return: Promise
withLock
If you want immutable data between related queries than run all queries in withLock.
function
fn
return: Promise
AbstractSQL
executeSQL
Execute sql queries with arguments args.
string
sqlArray.<*>
args
return: Promise.<Array>
AbstractSync
set
string
keystring
value
return: Promise
get
string
key
return: Promise.<?string>
remove
string
key
return: Promise
entries
return: Promise<Iterable<{key: string, value: string}>>
clear
string
key
return: Promise
Alternatives
License
This software is licensed under the MIT License.