Comparing version 0.1.4 to 0.1.5
@@ -157,3 +157,3 @@ !function(){ | ||
, mappingMap = this._mappingMap = {} | ||
, belongsToMap = {} | ||
, belongsToMap = this._belongsToMap = {} | ||
, referenceMap = this._referenceMap = {}; | ||
@@ -293,2 +293,11 @@ | ||
}.bind(this)); | ||
// generic belongsTo, mapping, refernce accessor | ||
properties.get = { | ||
value: function(targetName) { | ||
} | ||
} | ||
@@ -295,0 +304,0 @@ |
@@ -163,2 +163,3 @@ !function(){ | ||
// the name is used by a column, cannot reference directly | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
mapping.useGenericAccessor = true; | ||
@@ -169,2 +170,3 @@ } | ||
// we cannot use it | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
usedNames[name].useGenericAccessor = true; | ||
@@ -182,2 +184,3 @@ mapping.useGenericAccessor = true; | ||
if (model.columns[name]) { | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
// the name is used by a column, cannot reference directly | ||
@@ -187,2 +190,3 @@ beloning.useGenericAccessor = true; | ||
else if (usedNames[name]) { | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
// the name was used before by either a mapping or a reference | ||
@@ -200,2 +204,3 @@ // we cannot use it | ||
if (model.columns[name]) { | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
// the name is used by a column, cannot reference directly | ||
@@ -205,2 +210,3 @@ column.useGenericAccessor = true; | ||
else if (usedNames[name]) { | ||
log.warn('«'+model.name+'» cannot use the accessor «'+name+'», it\'s already used by another property'); | ||
// the name was used before by either a mapping or a reference | ||
@@ -207,0 +213,0 @@ // we cannot use it |
@@ -463,3 +463,8 @@ !function(){ | ||
, belongsToMap = {} | ||
, referenceMap = {}; | ||
, referenceMap = {} | ||
, description = {} | ||
, accessorMap = { | ||
get: {} | ||
, fetch: {} | ||
}; | ||
@@ -498,15 +503,21 @@ | ||
}).forEach(function(target){ | ||
accessorMap.get[target.name] = function() { | ||
return this._handleMapping(column, target, Array.prototype.slice.call(arguments), true); | ||
}; | ||
accessorMap.fetch[target.name] = function() { | ||
return this._handleMapping(column, target, Array.prototype.slice.call(arguments)); | ||
}; | ||
description[this._getAccessorName(target.name)] = 'Mapping accessor for the «'+target.name+'» Model'; | ||
description[this._getAccessorName(target.name, true)] = 'Mapping accessor for the «'+target.name+'» Model'; | ||
//log.warn(definition.name, column.name, target.model.name, this.mapperGetterName(target.model.name), target.via.model.name); | ||
Object.defineProperty(QB, this._getAccessorName(target.name), { | ||
value: function() { | ||
return this._handleMapping(column, target, Array.prototype.slice.call(arguments), true); | ||
} | ||
, enumerable: true | ||
value : accessorMap.get[target.name] | ||
, enumerable : true | ||
}); | ||
Object.defineProperty(QB, this._getAccessorName(target.name, true), { | ||
value: function() { | ||
return this._handleMapping(column, target, Array.prototype.slice.call(arguments)); | ||
} | ||
, enumerable: true | ||
value : accessorMap.fetch[target.name] | ||
, enumerable : true | ||
}); | ||
@@ -524,9 +535,15 @@ }.bind(this)); | ||
if (!column.useGenericAccessor) { | ||
QB[this._getAccessorName(column.referencedModel.name)] = function() { | ||
accessorMap.get[column.referencedModel.name] = function() { | ||
return this._handleReference(column, column.referencedModel, Array.prototype.slice.call(arguments)); | ||
}; | ||
accessorMap.fetch[column.referencedModel.name] = function() { | ||
return this._handleReference(column, column.referencedModel, Array.prototype.slice.call(arguments), true); | ||
}; | ||
QB[this._getAccessorName(column.referencedModel.name, true)] = function() { | ||
return this._handleReference(column, column.referencedModel, Array.prototype.slice.call(arguments)); | ||
}; | ||
description[this._getAccessorName(column.referencedModel.name)] = 'Reference accessor for the «'+column.referencedModel.name+'» Model'; | ||
description[this._getAccessorName(column.referencedModel.name, true)] = 'Reference accessor for the «'+column.referencedModel.name+'» Model'; | ||
QB[this._getAccessorName(column.referencedModel.name, true)] = accessorMap.get[column.referencedModel.name]; | ||
QB[this._getAccessorName(column.referencedModel.name)] = accessorMap.fetch[column.referencedModel.name]; | ||
} | ||
@@ -548,14 +565,42 @@ } | ||
//log.warn(definition.name, column.name, target.name, this.mapperGetterName(target.name)); | ||
QB[this._getAccessorName(target.name)] = function() { | ||
accessorMap.get[target.name] = function() { | ||
return this._handleBelongsTo(column, target, Array.prototype.slice.call(arguments)); | ||
}; | ||
accessorMap.fetch[target.name] = function() { | ||
return this._handleBelongsTo(column, target, Array.prototype.slice.call(arguments), true); | ||
}; | ||
QB[this._getAccessorName(target.name, true)] = function() { | ||
return this._handleBelongsTo(column, target, Array.prototype.slice.call(arguments)); | ||
}; | ||
description[this._getAccessorName(target.name)] = 'Belongs to accessor for the «'+target.name+'» Model'; | ||
description[this._getAccessorName(target.name, true)] = 'Belongs to accessor for the «'+target.name+'» Model'; | ||
QB[this._getAccessorName(target.name, true)] = accessorMap.get[target.name]; | ||
QB[this._getAccessorName(target.name)] = accessorMap.fetch[target.name]; | ||
}.bind(this)); | ||
} | ||
}.bind(this)); | ||
// generic accessor for everything | ||
Object.defineProperty(QB, 'get', { | ||
value: function(targetName) { | ||
if (Object.hasOwnProperty.call(accessorMap.get, targetName)) { | ||
return accessorMap.get[targetName].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} | ||
else throw new Error('The QueryBuilder has no property «'+targetName+'»!'); | ||
} | ||
, enumerable: true | ||
}); | ||
Object.defineProperty(QB, 'fetch', { | ||
value: function(targetName) { | ||
if (Object.hasOwnProperty.call(accessorMap.fetch, targetName)) { | ||
return accessorMap.fetch[targetName].apply(this, Array.prototype.slice.call(arguments, 1)); | ||
} | ||
else throw new Error('The QueryBuilder has no property «'+targetName+'»!'); | ||
} | ||
, enumerable: true | ||
}); | ||
@@ -615,2 +660,13 @@ // generic accessors for mappings | ||
}); | ||
// describe methods function | ||
Object.defineProperty(QB, 'describeMethods', { | ||
value: function() { | ||
log(description); | ||
return this; | ||
} | ||
, enumerable: true | ||
}); | ||
@@ -617,0 +673,0 @@ |
{ | ||
"name" : "ee-orm" | ||
, "description" : "a simple yet powerful javascript orm for node.js" | ||
, "version" : "0.1.4" | ||
, "version" : "0.1.5" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" |
17
test.js
@@ -72,8 +72,13 @@ | ||
*/ | ||
//log(orm.eventbox.cityName(["*"])); | ||
/* | ||
orm.eventbox.city(["*"]).limit(10).get('cityName', ["*"]).find(function(err, list){ | ||
log(err, list); | ||
}) | ||
return; | ||
*/ | ||
orm.eventbox.event().describeMethods(); | ||
var transaction = orm.transaction() | ||
@@ -83,6 +88,6 @@ , query = transaction.eventbox.event(['*']).limit(10).offset(100); | ||
query.getMapping('event_media') | ||
query.getMapping('event_media'); | ||
query.getEventLocale(['subtitle', 'description']).getLanguage().filter({language: 'de'}); | ||
query.getVenue(['name', 'address'], {id: 82358}).fetchMapping('venue_media', ['*']).fetchReference('id_media', ['*']); | ||
query.getVenue(['name', 'address'], {id: 82358}).fetchMapping('venue_media', ['*']).fetchReference('id_media', ['*']).getCity(["*"]) | ||
query.getPerformer(['*']).getMedia(['*']); | ||
@@ -104,3 +109,3 @@ query.getCategory(['id']).getCategoryLocale(['name']).getLanguage().filter({language: 'de'}); | ||
//events.first().reload(); | ||
//log(events); | ||
log(events); | ||
/*events.forEach(function(event){ | ||
@@ -107,0 +112,0 @@ event.venues.forEach(function(venue){ |
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
78161
2199