Comparing version 0.3.20 to 0.3.21
@@ -6,3 +6,2 @@ !function(){ | ||
, async = require('ee-async') | ||
, RelatingSet = require('./RelatingSet') | ||
, EventEmitter = require('ee-event-emitter') | ||
@@ -9,0 +8,0 @@ , type = require('ee-types') |
@@ -126,2 +126,3 @@ !function(){ | ||
, getDatabase: thisContext.getDatabase | ||
, isMapping: true | ||
}); | ||
@@ -155,2 +156,3 @@ | ||
, getDatabase: thisContext.getDatabase | ||
, isMapping: false | ||
}); | ||
@@ -157,0 +159,0 @@ |
@@ -8,2 +8,3 @@ !function(){ | ||
, type = require('ee-types') | ||
, debug = require('ee-argv').has('dev-orm') | ||
, Set = require('./Set') | ||
@@ -22,6 +23,9 @@ , Query = require('./Query') | ||
if (type.object(input)) { | ||
if (type.function(input.isQuery)) return input; | ||
if (type.function(input.isModel)) return input; | ||
copy = {}; | ||
Object.keys(input).forEach(function(key){ | ||
copy[key] = input[key]; | ||
copy[key] = clone(input[key]); | ||
}); | ||
@@ -110,3 +114,3 @@ | ||
*/ | ||
, _handleReference: function(column, targetModel, queryParameters, returnTarget) { | ||
, _handleReference: function(column, targetModel, queryParameters, returnTarget) { if (debug) log.info('handleReference, from «'+this.tableName.yellow+'» to «'+targetModel.name.yellow+'» ...'); | ||
var select = this._getSelect(queryParameters) | ||
@@ -159,3 +163,3 @@ , filter = this._getFilters(queryParameters) | ||
, from : targetModelName | ||
, filter : clone(this._resource.query.filter) | ||
, filter : {} //clone(this._resource.query.filter) | ||
, group : group | ||
@@ -192,3 +196,3 @@ }) | ||
, _handleBelongsTo: function(column, targetModel, queryParameters, returnTarget) { | ||
, _handleBelongsTo: function(column, targetModel, queryParameters, returnTarget) { if (debug) log.info('handleBelongsTo, from «'+this.tableName.yellow+'» to «'+targetModel.name.yellow+'» ...'); | ||
var select = this._getSelect(queryParameters) | ||
@@ -223,3 +227,2 @@ , filter = this._getFilters(queryParameters) | ||
// create a child tree node for the querybuilder | ||
@@ -243,3 +246,3 @@ resource = new Resource({ | ||
, from : targetModelName | ||
, filter : clone(this._resource.query.filter) | ||
, filter : {} //clone(this._resource.query.filter) | ||
, group : group | ||
@@ -285,3 +288,3 @@ }) | ||
*/ | ||
, _handleMapping: function(column, targetModel, queryParameters, returnTarget){ | ||
, _handleMapping: function(column, targetModel, queryParameters, returnTarget){ if (debug) log.info('handleMapping, from «'+this.tableName.yellow+'» to «'+targetModel.name.yellow+'» ...'); | ||
var select = this._getSelect(queryParameters) | ||
@@ -353,3 +356,3 @@ , filter = this._getFilters(queryParameters) | ||
, from : targetModel.model.name | ||
, filter : clone(this._resource.query.filter) | ||
, filter : {} //clone(this._resource.query.filter) | ||
, group : group | ||
@@ -356,0 +359,0 @@ }) |
@@ -6,2 +6,3 @@ !function(){ | ||
, async = require('ee-async') | ||
, debug = require('ee-argv').has('dev-orm') | ||
, Set = require('./Set'); | ||
@@ -40,2 +41,7 @@ | ||
if (debug) { | ||
//log.highlight('Compiled queries, the resulting resource: '); | ||
//log(resource); | ||
} | ||
// execut ebase query | ||
@@ -167,2 +173,3 @@ this._executeQuery('query', resource.query, function(err, rows){ | ||
resource.children.forEach(function(childResource){ | ||
if (debug) log.info('preparing childResource «'+childResource.name.yellow+'», selected: '+((!!childResource.selected)+'').yellow+', hasRootFilter: '+((!!childResource.hasRootFilter)+'').yellow+', filtered: '+((!!childResource.filtered)+'').yellow+''); | ||
if (childResource.selected) this._selectParents(childResource); | ||
@@ -169,0 +176,0 @@ if (childResource.hasRootFilter) this._filterParents(childResource); |
@@ -6,2 +6,3 @@ !function(){ | ||
, async = require('ee-async') | ||
, debug = require('ee-argv').has('dev-orm') | ||
, Arguments = require('ee-arguments') | ||
@@ -101,2 +102,4 @@ , log = require('ee-log'); | ||
, _executeSave: {value: function(transaction, noReload, callback) { | ||
if (debug) log.info('Relatingset for «'+this._definition.name+'» is storing its items ...'); | ||
// check for query items | ||
@@ -141,2 +144,4 @@ var queries = []; | ||
else { | ||
if (debug) log.info('Relatingset for «'+this._definition.name+'» analyzed its changes: ['+(added.length+'').yellow+'] items were added, ['+(removed.length+'').red+'] items were removed ...'); | ||
// create / remove relational records | ||
@@ -193,2 +198,8 @@ async.wait(function(done){ | ||
// add to original records when saving was ok | ||
transaction.once('commit', function(){ | ||
this._originalRecords.push(record); | ||
}.bind(this)); | ||
if (debug) log.info('Relatingset for «'+this._definition.name+'» is storing a new relation record ...'); | ||
new this._orm[this._definition.model.getDatabaseName()][this._definition.via.model.name](values).save(transaction, next); | ||
@@ -209,2 +220,12 @@ } | ||
// remove records when deletion was successfull | ||
transaction.once('commit', function(){ | ||
var index = this._originalRecords.indexOf(record); | ||
if (index >= 0) this._originalRecords.splice(index, 1); | ||
index = this.indexOf(record); | ||
if (index >= 0) proto.splice.call(this, index, 1); | ||
}.bind(this)); | ||
if (debug) log.info('Relatingset for «'+this._definition.name+'» is deleting a relation record ...'); | ||
transaction[this._definition.via.model.name](values).delete(next) | ||
@@ -211,0 +232,0 @@ } |
@@ -5,2 +5,3 @@ !function(){ | ||
, EventEmitter = require('ee-event-emitter') | ||
, debug = require('ee-argv').has('dev-orm') | ||
, log = require('ee-log') | ||
@@ -25,3 +26,3 @@ , ORM; | ||
, filtered: {get: function() { | ||
return !!Object.keys(this.query.filter); | ||
return !!Object.keys(this.query.filter).length; | ||
}} | ||
@@ -47,9 +48,11 @@ | ||
Class.define(this, 'children', Class([]).Enumerable()) | ||
Class.define(this, 'relatingSets', Class({}).Enumerable()) | ||
this.hasRootFilter = this.filters && !!Object.keys(this.filters).length; | ||
this.hasRootFilter = this.filters && Object.keys(this.filters).length; | ||
if (this.primaryKeys) this.defaultSelect = this.defaultSelect.concat(this.primaryKeys); | ||
if (!ORM) ORM = require('./ORM'); | ||
@@ -59,2 +62,7 @@ | ||
if (this.parentResource) this.id = this.getUniqueId(); | ||
if (debug) { | ||
log.info('New resource ['+(this.id||this._id)+'] '+this.name.cyan+', has rootFilters: '+ ((!!this.hasRootFilter)+'').yellow+', is selected: '+ ((!!this.selected)+'').yellow+''); | ||
} | ||
} | ||
@@ -136,10 +144,11 @@ | ||
// filter a childquery by my ids, this is only called on the root resource | ||
, applyFilter: function(resource) { | ||
var q = resource.query; | ||
/*if (!q.filter) q.filter = {}; | ||
if (!q.filter) q.filter = {}; | ||
if (!q.filter[this.name]) q.filter[this.name] = {}; | ||
q.filter[this.name][resource.referencedParentColumn] = ORM.in(this.set.getColumnValues(resource.referencedParentColumn));*/ | ||
q.filter[this.name][this.primaryKeys[0]] = ORM.in(this.set.getColumnValues(this.primaryKeys[0])); | ||
/*this.primaryKeys.forEach(function(pk){ | ||
/* this.primaryKeys.forEach(function(pk){ | ||
q.group.push({ | ||
@@ -149,4 +158,4 @@ table : this.name | ||
}); | ||
}.bind(this));*/ | ||
/* | ||
}.bind(this)); | ||
q.group.push({ | ||
@@ -153,0 +162,0 @@ table : this.name |
{ | ||
"name" : "ee-orm" | ||
, "description" : "An easy to use ORM for node.js. Supports eager loading, complex queries, joins, transactions, complex database clusters & connection pooling." | ||
, "version" : "0.3.20" | ||
, "version" : "0.3.21" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" |
@@ -349,4 +349,14 @@ # ee-orm | ||
#### Reserved Keywords | ||
##### QueryBuilder inner workings | ||
1. Collect all joins, filters for the query, apply them | ||
2. Collect all subqueries (eager loading) if it or any child is selected | ||
3. Join its parent resource, all resources down to the root resource | ||
4. filter with the «in» statement | ||
5. Enjoy | ||
#### Reserved Keywords (Outdated) | ||
On the ORM itself the following keywords are reserved (your database should not have a name which is listed below): | ||
@@ -353,0 +363,0 @@ |
37
test.js
@@ -26,18 +26,23 @@ | ||
db.event({id:2}, ['*']).fetchImage(['*']).findOne(function(err, evt){ | ||
if (err) cb(err); | ||
else { | ||
evt.dir(); | ||
evt.image[0].delete(function(err){ | ||
if (err) cb(err); | ||
else evt.dir(); | ||
}); | ||
} | ||
}); | ||
db.event(['*']).fetchImage(['*']).findOne(function(err, evt){ evt.dir(); | ||
if (err) cb(err); | ||
else { | ||
db.image(['*']).limit(2).find(function(err, images){ images.dir(); | ||
if (err) cb(err); | ||
else { | ||
evt.image.push(images[0]); | ||
evt.save(function(err){ | ||
if (err) cb(err); | ||
else { | ||
evt.image.push(images[1]); | ||
evt.save(function(err){ | ||
if (err) cb(err); | ||
db.event({id:evt.id}).fetchImage(['*']).findOne(cb); | ||
}); | ||
} | ||
}) | ||
} | ||
}); | ||
} | ||
}); | ||
return; | ||
@@ -44,0 +49,0 @@ |
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
179236
3367
486