10 KiB
Persistence
Handle every persistence-related task
Kind: global class
- Persistence
- new Persistence()
- instance
- .persistCachedDatabase(callback)
- .persistCachedDatabaseAsync() ⇒
Promise.<void>
- .compactDatafile([callback])
- .compactDatafileAsync()
- .setAutocompactionInterval(interval)
- .stopAutocompaction()
- .persistNewState(newDocs, [callback])
- .persistNewStateAsync(newDocs) ⇒
Promise
- .treatRawData(rawData) ⇒
Object
- .treatRawStream(rawStream, cb)
- .treatRawStreamAsync(rawStream) ⇒
Promise.<{data: Array.<document>, indexes: Object.<string, rawIndex>}>
- .loadDatabase(callback)
- .loadDatabaseAsync() ⇒
Promise.<void>
- static
- inner
- ~treatRawStreamCallback :
function
- ~treatRawStreamCallback :
new Persistence()
Create a new Persistence object for database options.db
Param | Type | Description |
---|---|---|
options.db | Datastore |
|
[options.corruptAlertThreshold] | Number |
Optional, threshold after which an alert is thrown if too much data is corrupt |
[options.nodeWebkitAppName] | string |
Optional, specify the name of your NW app if you want options.filename to be relative to the directory where Node Webkit stores application data such as cookies and local storage (the best place to store data in my opinion) |
[options.beforeDeserialization] | function |
Hook you can use to transform data after it was serialized and before it is written to disk. |
[options.afterSerialization] | function |
Inverse of |
persistence.persistCachedDatabase(callback)
Persist cached database This serves as a compaction function since the cache always contains only the number of documents in the collection while the data file is append-only so it may grow larger This is an internal function, use compactDataFile which uses the executor
Kind: instance method of Persistence
Param | Type | Description |
---|---|---|
callback | NoParamCallback |
Optional callback, signature: err |
persistence.persistCachedDatabaseAsync() ⇒ Promise.<void>
Persist cached database This serves as a compaction function since the cache always contains only the number of documents in the collection while the data file is append-only so it may grow larger This is an internal function, use compactDataFileAsync which uses the executor
Kind: instance method of Persistence
persistence.compactDatafile([callback])
Queue a rewrite of the datafile
Kind: instance method of Persistence
Param | Type | Default | Description |
---|---|---|---|
[callback] | NoParamCallback |
() => {} |
Optional callback, signature: err |
persistence.compactDatafileAsync()
Queue a rewrite of the datafile
Kind: instance method of Persistence
persistence.setAutocompactionInterval(interval)
Set automatic compaction every interval ms
Kind: instance method of Persistence
Param | Type | Description |
---|---|---|
interval | Number |
in milliseconds, with an enforced minimum of 5 seconds |
persistence.stopAutocompaction()
Stop autocompaction (do nothing if autocompaction was not running)
Kind: instance method of Persistence
persistence.persistNewState(newDocs, [callback])
Persist new state for the given newDocs (can be insertion, update or removal) Use an append-only format
Kind: instance method of Persistence
Param | Type | Default | Description |
---|---|---|---|
newDocs | Array.<string> |
Can be empty if no doc was updated/removed |
|
[callback] | NoParamCallback |
() => {} |
Optional, signature: err |
persistence.persistNewStateAsync(newDocs) ⇒ Promise
Persist new state for the given newDocs (can be insertion, update or removal) Use an append-only format
Kind: instance method of Persistence
Param | Type | Description |
---|---|---|
newDocs | Array.<document> |
Can be empty if no doc was updated/removed |
persistence.treatRawData(rawData) ⇒ Object
From a database's raw data, return the corresponding machine understandable collection
Kind: instance method of Persistence
Param | Type | Description |
---|---|---|
rawData | string |
database file |
persistence.treatRawStream(rawStream, cb)
From a database's raw data stream, return the corresponding machine understandable collection
Kind: instance method of Persistence
Param | Type |
---|---|
rawStream | Readable |
cb | treatRawStreamCallback |
persistence.treatRawStreamAsync(rawStream) ⇒ Promise.<{data: Array.<document>, indexes: Object.<string, rawIndex>}>
From a database's raw data stream, return the corresponding machine understandable collection
Kind: instance method of Persistence
Param | Type |
---|---|
rawStream | Readable |
persistence.loadDatabase(callback)
Load the database
- Create all indexes
- Insert all data
- Compact the database This means pulling data out of the data file or creating it if it doesn't exist Also, all data is persisted right away, which has the effect of compacting the database file This operation is very quick at startup for a big collection (60ms for ~10k docs)
Kind: instance method of Persistence
Param | Type | Description |
---|---|---|
callback | NoParamCallback |
Optional callback, signature: err |
persistence.loadDatabaseAsync() ⇒ Promise.<void>
Load the database
- Create all indexes
- Insert all data
- Compact the database This means pulling data out of the data file or creating it if it doesn't exist Also, all data is persisted right away, which has the effect of compacting the database file This operation is very quick at startup for a big collection (60ms for ~10k docs)
Kind: instance method of Persistence
Persistence.ensureDirectoryExists(dir, [callback])
Check if a directory stat and create it on the fly if it is not the case
Kind: static method of Persistence
Param | Type | Default | Description |
---|---|---|---|
dir | string |
||
[callback] | NoParamCallback |
() => {} |
optional callback, signature: err |
Persistence.ensureDirectoryExistsAsync(dir) ⇒ Promise.<void>
Check if a directory stat and create it on the fly if it is not the case
Kind: static method of Persistence
Param | Type |
---|---|
dir | string |
Persistence.getNWAppFilename(appName, relativeFilename) ⇒ string
string
Deprecated
Return the path the datafile if the given filename is relative to the directory where Node Webkit stores data for this application. Probably the best place to store data
Kind: static method of Persistence
Param | Type |
---|---|
appName | string |
relativeFilename | string |
Persistence~treatRawStreamCallback : function
Kind: inner typedef of Persistence
Param | Type |
---|---|
err | Error |
data | Object |