Comparing version 0.8.4 to 0.8.5
@@ -381,5 +381,7 @@ !function(){ | ||
if (this._queryBuilderInstances[relationName]) { | ||
if (debug) log.warn('returning cached querybuilder for %s ...', targetModelName); | ||
// return cached qb instance | ||
@@ -386,0 +388,0 @@ instance = this._queryBuilderInstances[relationName]; |
@@ -132,2 +132,17 @@ !function () { | ||
/* | ||
* has a filter? | ||
*/ | ||
, hasFilters: function() { | ||
if (this._hasFilter) return true; | ||
else { | ||
if (this.filters && Object.keys(this.filters).length) { | ||
this._hasFilter = true; | ||
return true; | ||
} | ||
else return false; | ||
} | ||
} | ||
/* | ||
* return the filter object | ||
@@ -304,14 +319,7 @@ */ | ||
// we nede to apply our filter to all parent queries | ||
// execpt for the root resource (thats happened already) | ||
// all subselects need to be filtered in the same way as | ||
// the parent was filtered | ||
this.applyFiltersToParents(resource.getParent(), resource); | ||
// find leaf nodes, prepare the root with all children | ||
if (resource.hasChildren()) { | ||
resource.getChildren().forEach(function(childResource) { | ||
// select | ||
// add selects, joins and filters to the root query | ||
childResource.prepareRootQuery(); | ||
@@ -323,2 +331,13 @@ | ||
} | ||
// we need to apply our filter to all parent queries | ||
// execpt for the root resource (thats happened already | ||
// using the prepareRootQuery method). | ||
// all subselects need to be filtered in the same way as | ||
// their children are filtered | ||
if (resource.hasFiltersForTheRootResource() && resource.hasParent() && !resource.getParent().isRootResource()) { | ||
if (debug) log.warn('%s has filters for the root resource, adding them to all parents ...', resource.name); | ||
this.applyFiltersToParents(resource.getParent(), resource, [], resource); | ||
} | ||
} | ||
@@ -391,59 +410,50 @@ | ||
* this is used to filter all subselects | ||
* | ||
* @param <Object> the current target resource -> a parent of of the sourceResource, may be null | ||
* @param <Object> sourceResource, the resource this process was started on | ||
* @apram <Array> an array containng all joins starting at the sourceResource to the current resource | ||
* @param <Object> lastTargetResource, the direct parent of the currentTargetResource, may be null | ||
*/ | ||
, applyFiltersToParents: function(currentTargetResource, sourceResource, joins, lastTargetResource) { | ||
if (!lastTargetResource) lastTargetResource = sourceResource; | ||
var name = sourceResource.query.from | ||
, filter = currentTargetResource.query.filter; | ||
/*log.warn('%s is applying its filters to the target %s; hasFiltersForTheRootResource %s; currentTargetResource %s; !currentTargetResource.isRootResource %s; !sourceResource.parentsFiltered %s;' | ||
, sourceResource.name | ||
, currentTargetResource ? currentTargetResource.name : undefined | ||
, sourceResource.hasFiltersForTheRootResource() | ||
, !!currentTargetResource, currentTargetResource ? !currentTargetResource.isRootResource() : undefined | ||
, !sourceResource.parentsFiltered);*/ | ||
if (debug) log.debug('[%s] applying filters on %s to the parent %s ...'.yellow, sourceResource.name, sourceResource.name, currentTargetResource.name); | ||
// has filter, current target is not root, filters not yet applied | ||
if (sourceResource.hasFiltersForTheRootResource() && currentTargetResource && !currentTargetResource.isRootResource() && !sourceResource.parentsFiltered) { | ||
var name = sourceResource.query.from | ||
, targetFilter; | ||
// should we add the joins of the parent? look on the current | ||
// resource if the joins of the parents were added already | ||
// aka: do we need to add the join from the parent to this resource? | ||
if (!currentTargetResource._appliedJoins[lastTargetResource.name]) { | ||
if (debug) log.debug('[%s] adding sub-join from %s to %s ...'.cyan, sourceResource.name, lastTargetResource.name, currentTargetResource.name); | ||
if (debug) log.debug('applying filters on %s to the parent %s ...', sourceResource.name, currentTargetResource.name); | ||
if (debug) log.debug('applying sub-join from %s to %s ...'.cyan, sourceResource.name, currentTargetResource.name); | ||
currentTargetResource._appliedJoins[lastTargetResource.name] = true; | ||
joins = lastTargetResource.joins.slice().reverse().concat(joins) | ||
} | ||
// if there are no joins, take a revered copy of mine | ||
if (!joins) joins = sourceResource.joins.slice().reverse(); | ||
// make sure there is an object to write to | ||
if (!currentTargetResource.query.filter[name]) currentTargetResource.query.filter[name] = {}; | ||
// copy my filters to the parent resource | ||
if (sourceResource.filters && Object.keys(sourceResource.filters).length) { | ||
targetFilter = currentTargetResource.query.filter[name]; | ||
// make sure there is an object to write to | ||
if (!filter[name]) filter[name] = {}; | ||
Object.keys(sourceResource.filters).forEach(function(key){ | ||
targetFilter[key] = sourceResource.filters[key]; | ||
}); | ||
} | ||
// apply the filters from the source to the current target | ||
Object.keys(sourceResource.getFilter()).forEach(function(key){ | ||
filter[name][key] = sourceResource.filters[key]; | ||
}); | ||
// take the joins, apply them to the parent | ||
joins.forEach(function(joinStatement) { | ||
currentTargetResource.query.join.push(joinStatement.reverseFormat()); | ||
}.bind(this)); | ||
// apply all collected joins to the target | ||
joins.forEach(function(joinStatement) { | ||
currentTargetResource.query.join.push(joinStatement.reverseFormat()); | ||
}.bind(this)); | ||
// we need to add ou filter and joins to all branches sourcing from here | ||
this._joinAndFilterSideTree(name, sourceResource.filters, joins, currentTargetResource, lastTargetResource); | ||
// tage the source, makes sure its not added twice | ||
sourceResource.parentsFiltered = true; | ||
// we need to add ou filter and joins to all branches sourcing from here | ||
this._joinAndFilterSideTree(name, sourceResource.getFilter(), joins, currentTargetResource, lastTargetResource); | ||
// we should not join any table twice, check if we joined this pair already | ||
if (sourceResource._joinApplied[currentTargetResource.name]) { | ||
this.applyFiltersToParents(currentTargetResource.getParent(), sourceResource, joins, currentTargetResource); | ||
} | ||
else { | ||
sourceResource._joinApplied[currentTargetResource.name] = true; | ||
this.applyFiltersToParents(currentTargetResource.getParent(), sourceResource, currentTargetResource.joins.slice().reverse().concat(joins), currentTargetResource); | ||
} | ||
// is there a non root parent? | ||
if (currentTargetResource.hasParent() && !currentTargetResource.getParent().isRootResource()) { | ||
this.applyFiltersToParents(currentTargetResource.getParent(), sourceResource, joins, currentTargetResource); | ||
} | ||
@@ -450,0 +460,0 @@ } |
{ | ||
"name" : "ee-orm" | ||
, "description" : "ORM for postgres and mysql. Loads and saves referenced entites, executes complex queries, supports joins, transactions, complex database clusters & connection pooling. No conventions." | ||
, "version" : "0.8.4" | ||
, "version" : "0.8.5" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" |
@@ -828,11 +828,6 @@ | ||
describe('[Connection Pooling]', function(){ | ||
it('should be able to insert 1000 items at once', function(done){ | ||
var i = 1000 | ||
, items = []; | ||
it('should be able to insert 1000 items in parallel', function(done){ | ||
this.timeout(120000); | ||
while(i--) items.push(i); | ||
async.each(items, function(nope, cb){ | ||
async.each(Array.apply(null, {length: 1000}), function(nope, cb){ | ||
new db.image({ | ||
@@ -843,4 +838,12 @@ url: Math.random()+"" | ||
}); | ||
it('should be able to query 1000 items in parallel', function(done) { | ||
this.timeout(120000); | ||
async.each(Array.apply(null, {length: 1000}), function(nope, cb){ | ||
db.event(['*']).find(cb); | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
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
269291
5163