Comparing version 2.9.2 to 2.9.4
@@ -10,3 +10,4 @@ /// <reference path="../nodelib/node.js"/> | ||
validate = require('./utils/validation'); | ||
validate = require('./utils/validation'), | ||
diff = require('./utils/diff'); | ||
@@ -130,2 +131,5 @@ | ||
if(!changes) { | ||
var validation = validate(schema, this.__state.modified, undefined, this.__state.model.extraValidators); | ||
if(!validation.passed) return callback(validation.toError()); | ||
var original = _.cloneDeep(this.__state.original); | ||
@@ -237,5 +241,3 @@ var modified = _.cloneDeep(this.__state.modified); | ||
/// <value type="Object">Set the value of this field. Changes may be committed by calling save() on this instance.</value> | ||
var validation = validate(schema[targetProperty], value, targetProperty, this.__state.model.extraValidators); | ||
if (!validation.passed) throw validation.toError(); | ||
$.__state.modified[targetProperty] = value; | ||
$.__state.modified[targetProperty] = value; | ||
}, | ||
@@ -275,4 +277,2 @@ enumerable: true | ||
set: function(value) { | ||
var validation = validate(validator, value, name, model.extraValidators); | ||
if(!validation.passed) throw validation.toError(); | ||
this.__state.modified[name] = value; | ||
@@ -309,35 +309,2 @@ }, | ||
var diffPatch = Instance.diff = function (oldDoc, newDoc, path) { | ||
/// <signature> | ||
/// <summary>Creates a differential update query for use by MongoDB</summary> | ||
/// <param name="oldDoc" type="Object">The original document prior to any changes</param> | ||
/// <param name="newDoc" type="Object">The document containing the changes made to the original document</param> | ||
/// </signature> | ||
"use strict"; | ||
var changes = {}; | ||
for (var k in newDoc) { | ||
if (Array.isArray(newDoc[k]) && Array.isArray(oldDoc[k])) { | ||
var different = newDoc.length !== oldDoc.length; | ||
for (var i = 0; i < newDoc[k].length && !different; i++) { | ||
if (oldDoc[k][i] !== newDoc[k][i]) different = true; | ||
} | ||
if (!different) continue; | ||
changes.$set = changes.$set || {}; | ||
changes.$set[(path ? (path + '.') : '') + k] = newDoc[k]; | ||
} | ||
else if (_.isPlainObject(newDoc[k]) && _.isPlainObject(oldDoc[k])) { | ||
// Make recursive diff update | ||
_.merge(changes, diffPatch(oldDoc[k], newDoc[k], (path ? (path + '.') : '') + k)); | ||
} | ||
else { | ||
if (oldDoc[k] === newDoc[k]) continue; | ||
changes.$set = changes.$set || {}; | ||
changes.$set[(path ? (path + '.') : '') + k] = newDoc[k]; | ||
} | ||
} | ||
return changes; | ||
}; | ||
Instance.diff = diff; |
@@ -83,9 +83,11 @@ /// <reference path="../nodelib/node.js"/> | ||
var _instance = null; | ||
Object.defineProperty(this, 'Instance', { | ||
value: Instance.forModel(this), | ||
get: function() { return _instance = _instance || Instance.forModel(this) }, | ||
enumerable: false | ||
}); | ||
var _cache = options.cache; | ||
Object.defineProperty(this, 'cache', { | ||
value: options.cache || new NoOpCache(), | ||
get: function() { return _cache = _cache || new NoOpCache(); }, | ||
enumerable: false | ||
@@ -92,0 +94,0 @@ }) |
{ | ||
"name": "iridium", | ||
"version": "2.9.2", | ||
"version": "2.9.4", | ||
"author": "Benjamin Pannell <admin@sierrasoftworks.com>", | ||
@@ -31,3 +31,13 @@ "description": "A custom lightweight ORM for MongoDB designed for power-users", | ||
"should": "*" | ||
} | ||
}, | ||
"keywords": [ | ||
"mongodb", | ||
"orm", | ||
"odm", | ||
"iridium", | ||
"validation", | ||
"transformation", | ||
"preprocessing" | ||
] | ||
} |
@@ -27,2 +27,4 @@ # Iridium [![Build Status](https://travis-ci.org/SierraSoftworks/Iridium.png?branch=master)](https://travis-ci.org/SierraSoftworks/Iridium) [![](https://badge.fury.io/js/iridium.png)](https://npmjs.org/package/iridium) | ||
Iridium allows the creation and use of plugins which can extend models and reduce duplicated code across models for common behavioural use cases. Plugins can provide custom validation, manipulate models at creation time and have the opportunity to extend instances when they are created. | ||
- **Automatic Query Generation** | ||
We understand that sometimes you don't want to structure your own queries - it's a hassle which you could do without especially when working with arrays. Thankfully, Iridium includes a powerful differential query generator which automatically generates the query necessary to store your changes without you raising a finger. | ||
@@ -51,3 +53,3 @@ ## Installation | ||
database.register('User', new iridium.Model('user', { | ||
database.register('User', new iridium.Model(database, 'user', { | ||
firstname: String, | ||
@@ -283,2 +285,18 @@ lastname: String, | ||
### Differential Queries | ||
In **v2.9.4** we added a powerful new differential query generator (codename Omnom) which allows you to easily make changes to your instances in code, and have Iridium handle the task of converting those changes to the most efficient query possible when you want to store those changes in MongoDB. | ||
Omnom allows you to do many things without needing to worry about how they are persisted to the database. These are some of the things that Omnom is well suited to handling. | ||
- Change properties or their children | ||
- Change the value of an array's element or its children | ||
- Remove elements from an array | ||
- Add elements to the end of an array | ||
- Selectively replacing an array's elements | ||
Unfortunately, there are a few limitations imposed by the way MongoDB handles queries - so when working with Iridium and Omnom we recommend you try to avoid doing the following. | ||
- Removing elements from an array while adding/changing others (will result in the array being replaced) | ||
- Inserting elements at the front of an array (consider reversing the array using a Concoction if you want a stack implementation that is fast) | ||
## Caching Framework | ||
@@ -382,2 +400,2 @@ Our caching framework allows basic queries to be served against a high performance cache, offloading requests from your database server and allowing you to more easily develop high performance applications that scale well to user demand. | ||
I'd also like to thank [dresende](https://github.com/dresende) and [dxg](https://github.com/dxg) from the [node-orm2](https://github.com/dresende/node-orm2) project for getting me introduced to Node and giving me many of the ideas for how a good ORM should be structured. If you're looking for an easy to use and more fully featured ORM with support for SQL and NoSQL databases, I'd seriously suggest giving [node-orm2](https://github.com/dresende/node-orm2) a try. | ||
I'd also like to thank [dresende](https://github.com/dresende) and [dxg](https://github.com/dxg) from the [node-orm2](https://github.com/dresende/node-orm2) project for getting me introduced to Node and giving me many of the ideas for how a good ORM should be structured. If you're looking for an easy to use and more fully featured ORM with support for SQL and NoSQL databases, I'd seriously suggest giving [node-orm2](https://github.com/dresende/node-orm2) a try. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
346697
69
6961
398