The reactive state management system and wrapper for IndexedDB.
Choxy allows you to easily handle, save data to IndexedDB
npm i choxy
import choxy from 'choxy'
choxy.add(key, value)
import choxy from 'choxy'
choxy.get(key)
import choxy from 'choxy'
choxy.update(key, newValue)
import choxy from 'choxy'
choxy.remove(key)
import choxy from 'choxy'
// Callback will trigger when value of key change. Method return id_watch
// With option is immediate = true then callback will trigger when init value
id = choxy.watch(key, callback, { immediate: true | false})
import choxy from 'choxy'
choxy.unwatch(key, id)
db = new choxy.idb('MyDatabase')
await db.version(1).create({
friends: '++id,name,age', // first field is id
customers: 'snn,name,age,&email' // With field is unique then add prefix '&' for field
})
nameDatabase
: nameDatabase what you want crate
version
: version of database. It necessary when you want create objectStore then version must greater current version
tables
: Object store with key is name table and type of value is string format primaryKey,field1,field2,...
++id
: primaryKey autoincrement start from 1
db = new choxy.idb('MyDatabase')
await db.init()
status = await db.query('customers').add({snn: '111-11-1111', name: 'john', email: 'john@gmail.com', age: 24})
If status equal true then add success and otherwise
status = await db.query('customers').delete('111-11-1111')
status = await db.query('customers').update('111-11-1111', {snn: '111-11-1111', name: 'john', email: 'john@gmail.com', age: 27})
status = await db.query('customers').clear()
entry = await db.query('customers').get('111-11-1111')
entries = await db.query('customers').getAll().offset(1).limit(4).sortBy((a,b) => b.age - a.age).toArray()
offset
: Get entries from index offset
limit
: Return limit entries
sortBy
: Take callback which similar Array.sort()
toArray
: Necessary return entries as array
count = await db.query('customers').count()
db.query('customers').forEach(entry => {
console.log('Key: ', entry.key, 'Value: ', entry.value)
})
await db.query(table).where(field).above(x)
await db.query(table).where(field).aboveOrEqual(x)
await db.query(table).where(field).below(y)
await db.query(table).where(field).belowOrEqual(y)
await db.query(table).where(field).between(x, y, equalX, equalY)
// equalX: false, equalY: false --> >= x and <= y
// equalX: false, equalY: true --> >=x and < y
// equalX: true, equalY: false --> < x and <= y
// equalX: true, equalY: true --> < x and < y