Sample App - ClientDataStore-Usage
Datastore implementation
-
DataStore is no sql with indexes. The implementation depends on the browser capability. If there is indexedDB support, it uses idb. Else it falls back to localStorage/Heap.
-
Every datastore instance will implement all the interface that the data-store exposes
-
Currently we have support for indexedDB/LocalSotrage/heap. We can extend it websql or which ever local storage it can use / a completely service based impl.
-
Promise based implementation. Every interface return a promise.
var ds = dataStore;ds;
Assume we need marks of all students in a class
Each student has
-
roll number (unique index)
-
subject1 mark
-
subject2 mark
-
subject3 mark
-
total
Create DB, Object stores, indexes
tableMeta
Code Sample
var dataStore = ;dataStore;
Insert data
studentData
Code sample
var meta = name: 'marksheet'dataStore;
Interfaces
init(dbName, metas)
Creates objectStores and indexes.
dbName - name of the database you want to create.
metas - Array that accepts list of ObjectStore(like table) and their indexes.
output - promise
promise resolution: empty
destory(dbName)
dbName - name of the database you want to create.
Deletes the provided database.
getStore(dbName)
metas Sample
insert(meta, data)
insert object(s) to the specified ObjectStore.
meta - Object with ObjectStore name
output - promise
promise resolution: empty
Sample
meta:
data:
select(meta, [filters])
Returns object(s) from the specified ObjectStore, based on the filter(s).
meta - Object with ObjectStore name and index name which will be used if its a non filter selectAll case
filters - {index, [filterData]}
output - promise
promise resolution: Array of objects matching the filters
Sample
meta:
filterData:
Returns records having rollnumber 1 or 22.
update(meta, filterData, data)
Updates object(s) in the specified ObjectStore, based on the filter(s) and provided data. If any property is set to undefined, those properties will be dropped when updating.
meta - Object with ObjectStore name
filter - {index, [filterData]}
data - {}
output - promise
promise resolution: empty
Sample
meta:
filterData:
data:
updates record will rollnumber 1 with the provided data.
remove(meta, filterData)
Delete object(s) in the specified ObjectStore, based on the filter(s). Not providing any filter will delete all entries.
meta - Object with ObjectStore name
filter - {index, [filterData]}
output - promise
promise resolution: empty
Sample
meta:
filterData:
Removes the record with rollnumber 1.