Storage class for freebird
Storage(fileName, maxNum)
Arguments:
fileName
(String): The path to the file where the data is persisted.maxNum
(Number): The maximum number that can be stored in this class.
Returns:
- (Object) objectBox (instance of Storage class)
Examples
{
// private
_count: Number
_maxNum: Number
_maxIndex: Number
_box: Object //created by Dict class
_db: Object //persistent datastore
}
Notice: id start from 1
-
isEmpty()
- whether the box is empty
- return Boolean
-
has(id) (?)
- is objectBox has the object of specify id
- id (Number): object id
- return Boolean
-
get(id)
- get the object of specify id
- id (Number): object id
- return Object
-
set(id, obj, callback)
- store object to the box and specify the object id, store object to database
- id (Number): object id
- obj (Object): object to be stored
- callback (_Function): get called when store to objectBox and database
-
add(obj, callback)
- store object to the box and store object to database
- obj (Object): object to be stored
- callback (_Function): get called when store to objectBox and database
-
remove(id, callback)
- remove the object of specify id and remove object from database
- id (Number): object id
- callback (_Function): get called when remove from objectBox and database
-
getMaxNum() (?)
- get the maximum number of box
- return Number
-
getCount() (?)
- obtain the number of objects in a box
- return Number
-
filter(path, value)
- iterates box and filter out the match object
- path (String): path to the object value
- value (Depends): the value you want to compare to each object in object box
- return Object[]
-
find(predicate)
- find the object in the box which is match predicate
- predicate (Array|Function|Object|String)
- return Object
-
exportAllIds()
- export all object id
- return Number[]
-
modify(id, path, snippet, callback)
- modify the value of given object path to database
- id (Number): device id
- path (String): path to the value which you want to modify
- snippet (Depends): the value of the object refer by path will be modified to snippet
- callback (_Function): get called when modification is completed
-
replace(id, path, value, callback)
- replace the value of given object path to database
- id (Number): device id
- path (String): path to the value which you want to replace
- value (Depends): the value of the object refer by path will be replaced to this value
- callback (Function): get called when replace property to database is completed
-
reload(callback)
- load each object from database to box
- callback (Function): get called when reload from database is completed
-
isFulfilled(callback)
- check whether the need to reload the box in each instance
- callback (Function): get called when the check is complete
-
mailtain(callback)
- Synchronize data between database and storage box, and update each data object to database.
- callback (Function): get called when maintain storage box is complete
Dict()
- elements (Object)
- has(key)
- check element of given has in dictionary or not
- get(key)
- get element by given key
- set(key, val)
- add element to dictionary by given key
- remove(key)
- remove element by given key