createdAt timestamp

pull/2/head
Louis Chatriot 9 years ago
parent b5a01246fe
commit ef8905adf0
  1. 11
      lib/datastore.js

@ -13,8 +13,9 @@ var customUtils = require('./customUtils')
/** /**
* Create a new collection * Create a new collection
* @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.timestampData Optional, defaults to false. If set to true, createdAt and updatedAt will be created and populated automatically (if not specified by user)
* @param {Boolean} options.nodeWebkitAppName Optional, specify the name of your NW app if you want options.filename to be relative to the directory where * @param {Boolean} options.inMemoryOnly Optional, defaults to false
* @param {String} 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) * Node Webkit stores application data such as cookies and local storage (the best place to store data in my opinion)
* @param {Boolean} options.autoload Optional, defaults to false * @param {Boolean} options.autoload Optional, defaults to false
* @param {Function} options.onload Optional, if autoload is used this will be called after the load database with the error object as parameter. If you don't pass it the error will be thrown * @param {Function} options.onload Optional, if autoload is used this will be called after the load database with the error object as parameter. If you don't pass it the error will be thrown
@ -319,10 +320,10 @@ Datastore.prototype.prepareDocumentForInsertion = function (newDoc) {
preparedDoc = []; preparedDoc = [];
newDoc.forEach(function (doc) { preparedDoc.push(self.prepareDocumentForInsertion(doc)); }); newDoc.forEach(function (doc) { preparedDoc.push(self.prepareDocumentForInsertion(doc)); });
} else { } else {
if (newDoc._id === undefined) { if (newDoc._id === undefined) { newDoc._id = this.createNewId(); }
newDoc._id = this.createNewId();
}
preparedDoc = model.deepCopy(newDoc); preparedDoc = model.deepCopy(newDoc);
//if (preparedDoc._id === undefined) { preparedDoc._id = this.createNewId(); }
if (this.timestampData && preparedDoc.createdAt === undefined) { preparedDoc.createdAt = new Date(); }
model.checkObject(preparedDoc); model.checkObject(preparedDoc);
} }

Loading…
Cancel
Save