Storage
Storage and Storage.Index classes provide built-in data persistence - transparent data storage and retrieval using just JavaScript means.
Introduction and usage manual.
Architecture explained.
class Storage
Represents persistent storage.
Properties
root
object, root object in the storage. Read/write property.
Methods
open
Storage.open(filepath : string [,allowWrite: true [, password: string ]] ) : storage | null
Static method. Opens storage and returns an instance of Storage object.
Parameters:
- filepath - string, required. Absolute path in local filesystem of the DB file.
- allowWrite - boolean, optional. If it is false then storage is opened in read-only mode.
- password - string, optional. If password is provided then the function creates and opens file in encrypted mode.
close
storage.close()
Closes underlying Storage. Commits all data before closing. After closing the storage all persistent objects that are still in use are set to non-persistent state.
commit
storage.commit()
Commits (writes) all persistent objects reachable from its root into storage. Does not close the storage.
Use this method after complex or critical data modifications.
createIndex
storage.createIndex(type : string [, unique: bool]) returns: Index | null
Creates an index of given type and returns the index object. Index can have unique or duplicated keys depending on unique argument.
parameters:
- type, string, one of:
- "integer" - int32 keys
- "long" - int64 keys
- "float"
- "date"
- "string"
- unique, boolean, if true then the index supports only unique keys. Default value for is true.
registerClass
storage.registerClass(cls)
Registers class (a.k.a. constructor function in terms of ES5) of persistable objects.
When an object is stored into DB, name of its class is also stored. When the object is fetched from the DB, it gets the class assigned automatically if that class was registered before.