|
|
@ -15,6 +15,8 @@ var fs = require('fs') |
|
|
|
* @param {String} options.filename Optional, datastore will be in-memory only if not provided |
|
|
|
* @param {String} options.filename Optional, datastore will be in-memory only if not provided |
|
|
|
* @param {Boolean} options.inMemoryOnly Optional, default to false |
|
|
|
* @param {Boolean} options.inMemoryOnly Optional, default to false |
|
|
|
* @param {Boolean} options.pipeline Optional, defaults to false, pipeline appends to the data file (enable to return before writes are persisted to disk for greater speed) |
|
|
|
* @param {Boolean} options.pipeline Optional, defaults to false, pipeline appends to the data file (enable to return before writes are persisted to disk for greater speed) |
|
|
|
|
|
|
|
* @param {Boolean} options.nodeWebkitAppName 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) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function Datastore (options) { |
|
|
|
function Datastore (options) { |
|
|
|
var filename; |
|
|
|
var filename; |
|
|
@ -31,6 +33,7 @@ function Datastore (options) { |
|
|
|
this.pipeline = options.pipeline || false; |
|
|
|
this.pipeline = options.pipeline || false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determine whether in memory or persistent
|
|
|
|
if (!filename || typeof filename !== 'string' || filename.length === 0) { |
|
|
|
if (!filename || typeof filename !== 'string' || filename.length === 0) { |
|
|
|
this.filename = null; |
|
|
|
this.filename = null; |
|
|
|
this.inMemoryOnly = true; |
|
|
|
this.inMemoryOnly = true; |
|
|
@ -38,6 +41,11 @@ function Datastore (options) { |
|
|
|
this.filename = filename; |
|
|
|
this.filename = filename; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For NW apps, store data in the same directory where NW stores application data
|
|
|
|
|
|
|
|
if (this.filename && options.nodeWebkitAppName) { |
|
|
|
|
|
|
|
this.filename = customUtils.getNWAppFilename(options.nodeWebkitAppName, this.filename); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.executor = new Executor(); |
|
|
|
this.executor = new Executor(); |
|
|
|
if (this.pipeline) { this.persistenceExecutor = new Executor(); } |
|
|
|
if (this.pipeline) { this.persistenceExecutor = new Executor(); } |
|
|
|
|
|
|
|
|
|
|
@ -581,5 +589,4 @@ Datastore.prototype.remove = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Datastore; |
|
|
|
module.exports = Datastore; |
|
|
|