Comparing version 0.8.5 to 0.9.0
@@ -226,3 +226,3 @@ !function(){ | ||
(transaction || this._getDatabase()).executeQuery(query, function(err, data){ | ||
(transaction || this._getDatabase()).executeQuery(query, function(err, data) { | ||
if (err) callback(err); | ||
@@ -702,6 +702,6 @@ else { | ||
// yeah, we got some result from mysql which can't handle compund keys | ||
if (result.id) { | ||
// mysql doesn't support compund primaries, check fo that | ||
if (result.id !== undefined) { | ||
// mysql doesn't support compund primaries, check fro that | ||
if (this._defintion.primaryKeys.length === 1) { | ||
this[this._defintion.primaryKeys[0]] = result._mysql_id; | ||
this[this._defintion.primaryKeys[0]] = result.id; | ||
} | ||
@@ -708,0 +708,0 @@ else { |
@@ -33,2 +33,10 @@ !function(){ | ||
// driver names | ||
, _driverNames: { | ||
postgres : 'ee-postgres-connection' | ||
, mysql : 'ee-mysql-connection' | ||
} | ||
/* | ||
@@ -52,3 +60,3 @@ * class constructor, initialize everything | ||
, database : dbName | ||
, port : 5432 | ||
, port : rdbmsType === 'mysql' ? 3306 : 5432 | ||
, mode : 'readwrite' | ||
@@ -76,2 +84,7 @@ }); | ||
// let the user create a new schema | ||
this.Schema = function() { | ||
}.bind(this) | ||
// db connectivity | ||
@@ -82,3 +95,13 @@ this._initializeDatabases(options); | ||
/* | ||
* | ||
*/ | ||
, createSchema: function(name, databaseName) { | ||
} | ||
/* | ||
* accepts extension to the orm | ||
@@ -370,3 +393,3 @@ */ | ||
*/ | ||
, _initializeDatabases: function(options){ | ||
, _initializeDatabases: function(options) { | ||
if (type.object(options)) { | ||
@@ -382,3 +405,4 @@ Object.keys(options).forEach(function(databaseName){ | ||
this._databases[databaseName] = new DBCluster({type: options[databaseName].type}); | ||
// load db cluster | ||
this._databases[databaseName] = new DBCluster({}, this._loadDriver(options[databaseName].type)); | ||
@@ -393,3 +417,28 @@ options[databaseName].hosts.forEach(function(config){ | ||
} | ||
/** | ||
* load a connection driver by type | ||
* | ||
* @param <String> driver type | ||
*/ | ||
, _loadDriver: function(type) { | ||
var driver; | ||
if (this._driverNames[type]) { | ||
try { | ||
driver = require(this._driverNames[type]); | ||
} catch (e) { | ||
throw new Error('Failed to load connection driver for type «'+type+'» :'+e); | ||
} | ||
return driver; | ||
} | ||
else throw new Error('Failed to load connection driver for type «'+type+'» !'); | ||
} | ||
}); | ||
@@ -404,3 +453,4 @@ | ||
// export | ||
module.exports = ORM; | ||
}(); |
@@ -46,3 +46,12 @@ !function(){ | ||
/* | ||
* returns the current offset | ||
*/ | ||
, getOffset: function() { | ||
return this.offset || 0; | ||
} | ||
/* | ||
* configre the offset | ||
@@ -49,0 +58,0 @@ */ |
@@ -621,3 +621,3 @@ !function(){ | ||
this._resource.query.order.push({ | ||
entity : this.tableName+this._resource.id | ||
entity : this.tableName+(this.getResource().isRootResource() ? this._resource.id : '') | ||
, property : column | ||
@@ -716,9 +716,125 @@ , desc : !!desc | ||
/* | ||
* execute a select query. All parameters can be passed in any | ||
* order. the returned data may be inconsistent (fetched in n | ||
* calls using the same filter but a different offset) when | ||
* working with the setSize parameter | ||
* | ||
* when a setSize is passed to this function a callback is not | ||
* optional, not even when using promises. the callback gets | ||
* called until there is no more data or tha action was aborted | ||
* | ||
* @returns this or a promise | ||
* | ||
* @param <Number> optional, set size to return. the | ||
* callback will be called until all | ||
* records were returned | ||
* @param <Function> optional, callback that will be called | ||
* with the results | ||
* @param <Object> optional, a transaction object on which | ||
* the query must be executed. | ||
*/ | ||
, find: function() { | ||
var i = 0 | ||
, l = arguments.length | ||
, query = this.getRootResource().getQuery() | ||
, offset, callback, transaction, setSize; | ||
, find: function(callback, transaction) { | ||
return this._execute(callback, transaction, 'find'); | ||
for (; i < l; i++) { | ||
switch(typeof arguments[i]) { | ||
case 'function': | ||
callback = arguments[i]; | ||
break; | ||
case 'number': | ||
setSize = arguments[i]; | ||
break; | ||
case 'object': | ||
transaction = arguments[i]; | ||
break; | ||
} | ||
} | ||
// maybe we need to fetch the data in n sets | ||
if (setSize) { | ||
if (!callback) return Promise.reject(new Errro('The «find» method was called with the setSize parameter but without a callback. Please call this method with a callback which will be called for each set!')); | ||
// get the start offset | ||
offset = query.getOffset(); | ||
// set limit | ||
query.setLimit(setSize); | ||
// always return a promise, when in callback mode | ||
// this will be ignored by the user and he has to observe | ||
// by himself when he got the last set which is if the | ||
// last parameter is delivered. | ||
return new Promise(function(resolve, reject) { | ||
var abort | ||
, next; | ||
abort = function() { | ||
reject(new Error('qb.find: action aborted by the user!')); | ||
}; | ||
next = function() { | ||
// set new offset | ||
query.setOffset(offset); | ||
// increase offset | ||
offset += setSize; | ||
// get data | ||
this._execute(function(err, data) { | ||
if (err) { | ||
callback(err); | ||
reject(err); | ||
} | ||
else { | ||
// check if we're finished | ||
if (data.length < setSize) { | ||
callback(null, data, function(){}, function(){}, true); | ||
resolve(); | ||
} | ||
// let the user get more records | ||
else callback(null, data, next, abort, false); | ||
} | ||
}, transaction, 'find'); | ||
}.bind(this); | ||
// first round | ||
next(); | ||
}.bind(this)); | ||
} | ||
else return this._execute(callback, transaction, 'find'); | ||
} | ||
, findOne: function(callback, transaction) { | ||
/* | ||
* find one record. pass arguments in any order. | ||
* | ||
* @param <Object> optional, transaction | ||
* @param <Function> optional, callback | ||
* | ||
*/ | ||
, findOne: function() { | ||
var i = 0 | ||
, l = arguments.length | ||
, callback, transaction; | ||
for (; i < l; i++) { | ||
switch(typeof arguments[i]) { | ||
case 'function': | ||
callback = arguments[i]; | ||
break; | ||
case 'object': | ||
transaction = arguments[i]; | ||
break; | ||
} | ||
} | ||
return this._execute(callback, transaction, 'findOne'); | ||
@@ -728,12 +844,32 @@ } | ||
, count: function(callback, transaction, column) { | ||
if (type.string(transaction)) { | ||
column = transaction; | ||
transaction = null; | ||
/* | ||
* count records. pass arguments in any order. | ||
* | ||
* @param <Object> optional, transaction | ||
* @param <Function> optional, callback | ||
* @param <String> optional, column to count on | ||
* | ||
*/ | ||
, count: function() { | ||
var i = 0 | ||
, l = arguments.length | ||
, callback, transaction, column; | ||
for (; i < l; i++) { | ||
switch(typeof arguments[i]) { | ||
case 'function': | ||
callback = arguments[i]; | ||
break; | ||
case 'object': | ||
transaction = arguments[i]; | ||
break; | ||
case 'string': | ||
column = arguments[i]; | ||
break; | ||
} | ||
} | ||
else if (type.string(callback)) { | ||
column = callback; | ||
callback = null; | ||
} | ||
return this._execute(callback, transaction, 'count', column); | ||
@@ -743,3 +879,27 @@ } | ||
, delete: function(callback, transaction) { | ||
/* | ||
* bulk delete. pass arguments in any order. | ||
* | ||
* @param <Object> optional, transaction | ||
* @param <Function> optional, callback | ||
* | ||
*/ | ||
, delete: function() { | ||
var i = 0 | ||
, l = arguments.length | ||
, callback, transaction; | ||
for (; i < l; i++) { | ||
switch(typeof arguments[i]) { | ||
case 'function': | ||
callback = arguments[i]; | ||
break; | ||
case 'object': | ||
transaction = arguments[i]; | ||
break; | ||
} | ||
} | ||
return this._execute(callback, transaction, 'delete'); | ||
@@ -749,3 +909,29 @@ } | ||
, update: function(values, callback, transaction) { | ||
/* | ||
* bulk update. pass arguments in any order. | ||
* | ||
* @param <Object> optional, transaction | ||
* @param <Function> optional, callback | ||
* @param <Object> values to set on the records to update | ||
* | ||
*/ | ||
, update: function() { | ||
var i = 0 | ||
, l = arguments.length | ||
, callback, transaction, values; | ||
for (; i < l; i++) { | ||
switch(typeof arguments[i]) { | ||
case 'function': | ||
callback = arguments[i]; | ||
break; | ||
case 'object': | ||
if (arguments[i] !== null && typeof arguments[i].isTransaction === 'function' && arguments[i].isTransaction()) transaction = arguments[i]; | ||
else values = arguments[i]; | ||
break; | ||
} | ||
} | ||
this._rootResource.query.values = values; | ||
@@ -752,0 +938,0 @@ |
@@ -50,2 +50,5 @@ !function () { | ||
// indicate if the query was prepared already | ||
, _isPrepared: false | ||
// if this resource has ordering that must be applied to the root resource | ||
@@ -259,2 +262,8 @@ // use this.order.length instead | ||
// abort when the query was prepared alreay | ||
if (this._isPrepared) return; | ||
// mark as prepared | ||
this._isPrepared = true; | ||
// emit event for extensions | ||
@@ -261,0 +270,0 @@ this._emitEvent('beforePrepare', this, this.getDefinition()); |
{ | ||
"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.5" | ||
, "version" : "0.9.0" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -26,6 +26,6 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" | ||
, "ee-arguments" : "1.0.x" | ||
, "ee-db-cluster" : "0.1.x" | ||
, "ee-mysql-connection" : "^0.2.0" | ||
, "ee-postgres-connection" : "^0.4.0" | ||
, "es6-promise" : "2.0.0" | ||
, "ee-db-cluster" : "0.2.x" | ||
, "ee-mysql-connection" : "0.3.x" | ||
, "ee-postgres-connection" : "0.5.x" | ||
, "es6-promise" : "2.0.x" | ||
} | ||
@@ -32,0 +32,0 @@ , "devDependencies": { |
@@ -13,3 +13,3 @@ | ||
orm.load(function(err) { | ||
var db = orm.eventbooster | ||
var db = orm.ee_orm_test | ||
, start | ||
@@ -22,3 +22,5 @@ , count = 0 | ||
var evt = db.event(['*']) | ||
db.event(['*']).find(log); | ||
/*var evt = db.event(['*']) | ||
, ed = evt.getEventData(['*']); | ||
@@ -43,4 +45,4 @@ | ||
evt.find(log); | ||
evt.find(log);*/ | ||
}); |
1236
test/orm.js
@@ -24,4 +24,5 @@ | ||
['POSTGRES'].forEach(function(db){ | ||
var config | ||
['postgres', 'mysql'].forEach(function(dbType) { | ||
var databaseName = 'ee_orm_test_'+dbType | ||
, config | ||
, sqlStatments | ||
@@ -34,9 +35,8 @@ , key | ||
try { | ||
config = require('../config.js').db | ||
config = {}; | ||
config[databaseName] = require('../config.js').db[databaseName]; | ||
} catch(e) { | ||
config = { | ||
ee_orm_test: { | ||
ee_orm_test_postgres: { | ||
type: 'postgres' | ||
, timestamps: true | ||
, nestedSet: true | ||
, hosts: [ | ||
@@ -54,2 +54,15 @@ { | ||
} | ||
, ee_orm_test_mysql: { | ||
type: 'mysql' | ||
, hosts: [ | ||
{ | ||
host : 'localhost' | ||
, username : 'root' | ||
, password : '' | ||
, port : 3306 | ||
, mode : 'readwrite' | ||
, maxConnections: 50 | ||
} | ||
] | ||
} | ||
}; | ||
@@ -60,3 +73,3 @@ } | ||
// sql for test db | ||
sqlStatments = fs.readFileSync(__dirname+'/postgres.sql').toString().split(';').map(function(input){ | ||
sqlStatments = fs.readFileSync(__dirname+'/'+dbType+'.sql').toString().split(';').map(function(input){ | ||
return input.trim().replace(/\n/gi, ' ').replace(/\s{2,}/g, ' ') | ||
@@ -68,119 +81,120 @@ }).filter(function(item){ | ||
describe('['+dbType.toUpperCase()+']', function() { | ||
// connecting & rebvuilding the test database | ||
describe('The ORM', function(){ | ||
it('should be able to connect to the database', function(done){ | ||
this.timeout(5000); | ||
new ORM(config).load(function(err, ormObject) { | ||
if (err) done(err); | ||
else { | ||
orm = ormObject; | ||
done(); | ||
} | ||
// connecting & rebvuilding the test database | ||
describe('The ORM', function(){ | ||
it('should be able to connect to the database', function(done){ | ||
this.timeout(5000); | ||
new ORM(config).load(function(err, ormObject) { | ||
if (err) done(err); | ||
else { | ||
orm = ormObject; | ||
done(); | ||
} | ||
}); | ||
//orm.on('load', done); | ||
}); | ||
//orm.on('load', done); | ||
}); | ||
it('should be able to drop & create the testing schema ('+sqlStatments.length+' raw SQL queries)', function(done){ | ||
orm.getDatabase('ee_orm_test').getConnection(function(err, connection){ | ||
if (err) done(err); | ||
else { | ||
async.each(sqlStatments, connection.queryRaw.bind(connection), done); | ||
} | ||
}); | ||
}); | ||
it('should be able to drop & create the testing schema ('+sqlStatments.length+' raw SQL queries)', function(done){ | ||
orm.getDatabase(databaseName).getConnection(function(err, connection){ | ||
if (err) done(err); | ||
else { | ||
async.each(sqlStatments, connection.queryRaw.bind(connection), done); | ||
} | ||
}); | ||
}); | ||
it ('should be able to reload the models', function(done){ | ||
orm.reload(function(err){ | ||
if (err) done(err); | ||
else { | ||
db = orm.ee_orm_test; | ||
done(); | ||
} | ||
it ('should be able to reload the models', function(done) { | ||
orm.reload(function(err){ | ||
if (err) done(err); | ||
else { | ||
db = orm[databaseName]; | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
// inserting data into test database | ||
describe('Inserting Test Data', function(){ | ||
it('into the language table', function(done){ | ||
var index = 0 | ||
, items | ||
, insert; | ||
// inserting data into test database | ||
describe('Inserting Test Data', function() { | ||
it('into the language table', function(done) { | ||
var index = 0 | ||
, items | ||
, insert; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.language({code: items[index]}).save(function(err){ | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.language({code: items[index]}).save(function(err) { | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
items = ['en', 'de', 'nl', 'fr', 'it']; | ||
items = ['en', 'de', 'nl', 'fr', 'it']; | ||
insert(); | ||
}); | ||
insert(); | ||
}); | ||
it('into the country table', function(done){ | ||
async.each([ | ||
{code: 'ch', name: 'Switzerland'} | ||
], function(country, next){ | ||
new db.country(country).save(next); | ||
}, done); | ||
}); | ||
it('into the country table', function(done){ | ||
async.each([ | ||
{code: 'ch', name: 'Switzerland'} | ||
], function(country, next){ | ||
new db.country(country).save(next); | ||
}, done); | ||
}); | ||
it('into the county table', function(done){ | ||
var index = 0 | ||
, items | ||
, insert; | ||
it('into the county table', function(done){ | ||
var index = 0 | ||
, items | ||
, insert; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.county(items[index]).save(function(err){ | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.county(items[index]).save(function(err){ | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
items = [ | ||
{code: 'be', name: 'Bern', id_country: 1} | ||
, {code: 'zh', name: 'Zürich', id_country: 1} | ||
, {code: 'ge', name: 'Genf', id_country: 1} | ||
]; | ||
items = [ | ||
{code: 'be', name: 'Bern', id_country: 1} | ||
, {code: 'zh', name: 'Zürich', id_country: 1} | ||
, {code: 'ge', name: 'Genf', id_country: 1} | ||
]; | ||
insert(); | ||
}); | ||
insert(); | ||
}); | ||
it('into the municipality table', function(done){ | ||
var index = 0 | ||
, items | ||
, insert; | ||
it('into the municipality table', function(done){ | ||
var index = 0 | ||
, items | ||
, insert; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.municipality(items[index]).save(function(err){ | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
insert = function(){ | ||
if (index < items.length) { | ||
new db.municipality(items[index]).save(function(err){ | ||
if (err) done(err); | ||
else insert(); | ||
}); | ||
index++; | ||
} else done(); | ||
}; | ||
items = [ | ||
{name: 'Bern', id_county: 1} | ||
, {name: 'Ittigen', id_county: 1} | ||
, {name: 'Solothurn', id_county: 1} | ||
]; | ||
items = [ | ||
{name: 'Bern', id_county: 1} | ||
, {name: 'Ittigen', id_county: 1} | ||
, {name: 'Solothurn', id_county: 1} | ||
]; | ||
insert(); | ||
insert(); | ||
}); | ||
}); | ||
}); | ||
@@ -190,22 +204,22 @@ | ||
describe('Setting a new Accessor name for', function(){ | ||
it('the «image» reference on the «venue model» using an invalid identifier should fail', function(){ | ||
assert.throws(function(){ | ||
db.venue.setReferenceAccessorName('id_images', 'logo'); | ||
describe('Setting a new Accessor name for', function(){ | ||
it('the «image» reference on the «venue model» using an invalid identifier should fail', function(){ | ||
assert.throws(function(){ | ||
db.venue.setReferenceAccessorName('id_images', 'logo'); | ||
}); | ||
}); | ||
}); | ||
it('the «image» mapping on the «venue model» using an invalid identifier should fail', function(){ | ||
assert.throws(function(){ | ||
db.venue.setMappingAccessorName('venue_imaged', 'image'); | ||
it('the «image» mapping on the «venue model» using an invalid identifier should fail', function(){ | ||
assert.throws(function(){ | ||
db.venue.setMappingAccessorName('venue_imaged', 'image'); | ||
}); | ||
}); | ||
}); | ||
it('the «image» reference on the «venue model»', function(){ | ||
db.venue.setReferenceAccessorName('id_image', 'logo'); | ||
it('the «image» reference on the «venue model»', function(){ | ||
db.venue.setReferenceAccessorName('id_image', 'logo'); | ||
}); | ||
it('the «image» mapping on the «venue model»', function(){ | ||
db.venue.setMappingAccessorName('venue_image', 'images'); | ||
}); | ||
}); | ||
it('the «image» mapping on the «venue model»', function(){ | ||
db.venue.setMappingAccessorName('venue_image', 'images'); | ||
}); | ||
}); | ||
@@ -216,202 +230,202 @@ | ||
// insert tests | ||
describe('Inserting Data', function(){ | ||
it('into an entity', function(done){ | ||
var images = [ | ||
{url:'http://gfycat.com/ScentedPresentKingfisher.gif', expected:'{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}'} | ||
, {url:'http://imgur.com/XVch57C', expected:'{"id":2,"url":"http://imgur.com/XVch57C"}'} | ||
, {url:'http://i.imgur.com/fYaV6tK.gif', expected:'{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"}'} | ||
, {url:'http://i.imgur.com/OQa6gbp.gif', expected:'{"id":4,"url":"http://i.imgur.com/OQa6gbp.gif"}'} | ||
]; | ||
// insert tests | ||
describe('Inserting Data', function(){ | ||
it('into an entity', function(done){ | ||
var images = [ | ||
{url:'http://gfycat.com/ScentedPresentKingfisher.gif', expected:'{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}'} | ||
, {url:'http://imgur.com/XVch57C', expected:'{"id":2,"url":"http://imgur.com/XVch57C"}'} | ||
, {url:'http://i.imgur.com/fYaV6tK.gif', expected:'{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"}'} | ||
, {url:'http://i.imgur.com/OQa6gbp.gif', expected:'{"id":4,"url":"http://i.imgur.com/OQa6gbp.gif"}'} | ||
]; | ||
var insert = function(index){ | ||
if (index < images.length){ | ||
var config = images[index]; | ||
var insert = function(index){ | ||
if (index < images.length){ | ||
var config = images[index]; | ||
new db.image({ | ||
url: config.url | ||
}).save(function(err, image){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(image), config.expected); | ||
insert(++index); | ||
} | ||
}); | ||
new db.image({ | ||
url: config.url | ||
}).save(function(err, image){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(image), config.expected); | ||
insert(++index); | ||
} | ||
}); | ||
} | ||
else done(); | ||
} | ||
else done(); | ||
} | ||
insert(0); | ||
}); | ||
insert(0); | ||
}); | ||
it('with null as a column value should work', function(done){ | ||
new db.country({ | ||
code: 'nl' | ||
, name: null | ||
}).save(done); | ||
}); | ||
it('with null as a column value should work', function(done){ | ||
new db.country({ | ||
code: 'nl' | ||
, name: null | ||
}).save(done); | ||
}); | ||
it('with a reference fetched using a query', function(done){ | ||
new db.venue({ | ||
name: 'Dachstock Reitschule' | ||
, municipality: db.municipality(['*'], { | ||
name: 'Bern' | ||
}) | ||
, id_image: 1 | ||
}).save(function(err, image){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(image), '{"id":1,"municipality":{"id":1,"id_county":1,"name":"Bern"},"id_municipality":1,"name":"Dachstock Reitschule","id_image":1}'); | ||
it('with a reference fetched using a query', function(done){ | ||
new db.venue({ | ||
name: 'Dachstock Reitschule' | ||
, municipality: db.municipality(['*'], { | ||
name: 'Bern' | ||
}) | ||
, id_image: 1 | ||
}).save(function(err, image){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(image), '{"id":1,"municipality":{"id":1,"id_county":1,"name":"Bern"},"id_municipality":1,"name":"Dachstock Reitschule","id_image":1}'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('with a newly created reference which has an ambiguous name should fail', function(done){ | ||
try { | ||
new db.venue({ | ||
name: 'Dachstock Reitschule' | ||
, image: new db.image({url:'http://i.imgur.com/oP9R0pq.gif'}) | ||
, municipality: db.municipality({ | ||
name: 'Bern' | ||
}) | ||
}).save(); | ||
} catch (err) { | ||
assert.ok(err instanceof Error); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('with a newly created reference which has an ambiguous name should fail', function(done){ | ||
try { | ||
it('with a newly created reference on a redefined accessor', function(done){ | ||
new db.venue({ | ||
name: 'Dachstock Reitschule' | ||
, image: new db.image({url:'http://i.imgur.com/oP9R0pq.gif'}) | ||
, logo: new db.image({url:'http://i.imgur.com/oP9R0pq.gif'}) | ||
, images: [db.image({id:1})] | ||
, municipality: db.municipality({ | ||
name: 'Bern' | ||
}) | ||
}).save(); | ||
} catch (err) { | ||
assert.ok(err instanceof Error); | ||
done(); | ||
} | ||
}); | ||
}).save(done); | ||
}); | ||
it('with a newly created reference on a redefined accessor', function(done){ | ||
new db.venue({ | ||
name: 'Dachstock Reitschule' | ||
, logo: new db.image({url:'http://i.imgur.com/oP9R0pq.gif'}) | ||
, images: [db.image({id:1})] | ||
, municipality: db.municipality({ | ||
name: 'Bern' | ||
}) | ||
}).save(done); | ||
}); | ||
it('with a mapped entity fetched using a query', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, image: [db.image(['*'], {id: 1})] | ||
, venue: db.venue(['*'], {id:1}) | ||
}).save(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(event), '{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('with a mapped entity fetched using a query', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, image: [db.image(['*'], {id: 1})] | ||
, venue: db.venue(['*'], {id:1}) | ||
}).save(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(event), '{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
} | ||
it('with a new belongsto entity', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, venue: db.venue(['*'], {id:1}) | ||
, eventLocale: [new db.eventLocale({description: 'some text', language: db.language(['*'], {id:1})})] | ||
}).save(expect('{"eventLocale":[{"id_event":2,"language":{"id":1,"code":"en"},"id_language":1,"description":"some text"}],"id":2,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
}); | ||
it('with a new belongsto entity', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, venue: db.venue(['*'], {id:1}) | ||
, eventLocale: [new db.eventLocale({description: 'some text', language: db.language(['*'], {id:1})})] | ||
}).save(expect('{"eventLocale":[{"id_event":2,"language":{"id":1,"code":"en"},"id_language":1,"description":"some text"}],"id":2,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
it('with a new mapped entity', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, image: [new db.image({url: 'http://imgur.com/gallery/laxsJHr'})] | ||
, venue: db.venue(['*'], {id:1}) | ||
, canceled: true | ||
}).save(expect('{"image":[{"id":6,"url":"http://imgur.com/gallery/laxsJHr"}],"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
}); | ||
it('with a new mapped entity', function(done){ | ||
new db.event({ | ||
title: 'Mapping Test' | ||
, startdate: new Date(0) | ||
, image: [new db.image({url: 'http://imgur.com/gallery/laxsJHr'})] | ||
, venue: db.venue(['*'], {id:1}) | ||
, canceled: true | ||
}).save(expect('{"image":[{"id":6,"url":"http://imgur.com/gallery/laxsJHr"}],"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
}); | ||
// query tests | ||
describe('Querying Data', function(){ | ||
it('from an entitiy', function(done){ | ||
db.event({id:1}).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"id":1}]'); | ||
done(); | ||
} | ||
// query tests | ||
describe('Querying Data', function(){ | ||
it('from an entitiy', function(done){ | ||
db.event({id:1}).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"id":1}]'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('from an entitiy including a reference', function(done){ | ||
db.event({id:1}, ['*']).getVenue(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
it('from an entitiy including a reference', function(done){ | ||
db.event({id:1}, ['*']).getVenue(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('from an entitiy including a mapping', function(done){ | ||
db.event({id:1}, ['*']).getImage(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
it('from an entitiy including a mapping', function(done){ | ||
db.event({id:1}, ['*']).getImage(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('from an entitiy including an entity belonging to the current entity', function(done){ | ||
db.event({id:2}, ['*']).getEventLocale(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"eventLocale":[{"id_event":2,"id_language":1,"description":"some text"}],"id":2,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
it('from an entitiy including an entity belonging to the current entity', function(done){ | ||
db.event({id:2}, ['*']).getEventLocale(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"eventLocale":[{"id_event":2,"id_language":1,"description":"some text"}],"id":2,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
// complex query tests | ||
describe('Querying Data with advanced eager loading', function(){ | ||
it('through a mapping table', function(done){ | ||
db.event({id:2}).getEventLocale(['*']).fetchLanguage(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"eventLocale":[{"id_event":2,"language":{"id":1,"code":"en"},"id_language":1,"description":"some text"}],"id":2}]'); | ||
done(); | ||
} | ||
// complex query tests | ||
describe('Querying Data with advanced eager loading', function(){ | ||
it('through a mapping table', function(done){ | ||
db.event({id:2}).getEventLocale(['*']).fetchLanguage(['*']).find(function(err, events){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(events), '[{"eventLocale":[{"id_event":2,"language":{"id":1,"code":"en"},"id_language":1,"description":"some text"}],"id":2}]'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('with two mapepd entities', function(done){ | ||
db.image.setMappingAccessorName('venue_image', 'venue'); | ||
it('with two mapepd entities', function(done){ | ||
db.image.setMappingAccessorName('venue_image', 'venue'); | ||
db.event({id:1}).getImage(['*']).getVenue(['*']).find(expect('[{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif","venue":[{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5}]}],"id":1}]', done)); | ||
db.event({id:1}).getImage(['*']).getVenue(['*']).find(expect('[{"image":[{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif","venue":[{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5}]}],"id":1}]', done)); | ||
}); | ||
}); | ||
}); | ||
describe('Queriying mutliple times on the same querybuilder', function(){ | ||
it('should return the correct results', function(done){ | ||
var query = db.event(['*']); | ||
query.getVenue(['*']); | ||
query.getVenue(['*'], {id: ORM.or([1,2,3,4])}); | ||
query.getVenue(['*'], {name: ORM.like('Da%')}); | ||
describe('Queriying mutliple times on the same querybuilder', function(){ | ||
it('should return the correct results', function(done){ | ||
var query = db.event(['*']); | ||
query.getVenue(['*']); | ||
query.getVenue(['*'], {id: ORM.or([1,2,3,4])}); | ||
query.getVenue(['*'], {name: ORM.like('Da%')}); | ||
query.find(expect('[{"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
query.find(expect('[{"id":1,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
}); | ||
}); | ||
@@ -421,275 +435,322 @@ | ||
describe('Updating existing Data', function(){ | ||
it('for a simple entity using the loaded model should work', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.title = 'Changed title'; | ||
event.save(expect('{"id":1,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
} | ||
describe('Updating existing Data', function(){ | ||
it('for a simple entity using the loaded model should work', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.title = 'Changed title'; | ||
event.save(expect('{"id":1,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('for a simple entity with two updates using the loaded model should work', function(done){ | ||
new db.event({ | ||
startdate: new Date() | ||
, title: 'bender' | ||
, venue: db.venue({id:1}, ['*']) | ||
}).save(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.title = 'Changed title'; | ||
event.enddate = new Date(1400000000000); | ||
event.startdate = new Date(0); | ||
event.save(expect('{"id":4,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
} | ||
it('for a simple entity with two updates using the loaded model should work', function(done){ | ||
new db.event({ | ||
startdate: new Date() | ||
, title: 'bender' | ||
, venue: db.venue({id:1}, ['*']) | ||
}).save(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.title = 'Changed title'; | ||
event.enddate = new Date(1400000000000); | ||
event.startdate = new Date(0); | ||
event.save(expect('{"id":4,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('with a reference fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getVenue(['*']).findOne(expect('{"id":1,"venue":{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5},"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
it('with a reference fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getVenue(['*']).findOne(expect('{"id":1,"venue":{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5},"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('with a new reference', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = new db.venue({ | ||
name: 'another venue' | ||
, logo: db.image({id:1}) | ||
, municipality: db.municipality({id:1}) | ||
}); | ||
it('with a new reference', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = new db.venue({ | ||
name: 'another venue' | ||
, logo: db.image({id:1}) | ||
, municipality: db.municipality({id:1}) | ||
}); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getVenue(['*']).findOne(expect('{"id":1,"venue":{"id":3,"id_municipality":1,"name":"another venue","id_image":1},"id_venue":3,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getVenue(['*']).findOne(expect('{"id":1,"venue":{"id":3,"id_municipality":1,"name":"another venue","id_image":1},"id_venue":3,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('with a mapping fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.image.push(db.image({id:3})); | ||
it('with a mapping fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.image.push(db.image({id:3})); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getImage(['*']).findOne(expect('{"image":[{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"},{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
event.save(function(err) { | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getImage(['*']).order('id', true).findOne(expect('{"image":[{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"},{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('with a new mapping record', function(done){ | ||
db.event({id:2}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.image.push(new db.image({url:'http://i.imgur.com/1vjB9yu.gif'})); | ||
it('with a new mapping record', function(done){ | ||
db.event({id:2}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.image.push(new db.image({url:'http://i.imgur.com/1vjB9yu.gif'})); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:2},['*']).getImage(['*']).findOne(expect('{"image":[{"id":7,"url":"http://i.imgur.com/1vjB9yu.gif"}],"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:2},['*']).getImage(['*']).findOne(expect('{"image":[{"id":7,"url":"http://i.imgur.com/1vjB9yu.gif"}],"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
} | ||
}); | ||
}); | ||
/*it('with a belonging record fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.eventLocale.push(db.eventLocale().getLanguage({id:1}).limit(1)); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getEventLocale(['*']).findOne(expect('{"image":[{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"},{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null}', done)); | ||
}); | ||
} | ||
}); | ||
});*/ | ||
}); | ||
/*it('with a belonging record fetched using a query', function(done){ | ||
db.event({id:1}).findOne(function(err, event){ | ||
if (err) done(err); | ||
else { | ||
event.venue = db.venue({id:2}); | ||
event.eventLocale.push(db.eventLocale().getLanguage({id:1}).limit(1)); | ||
event.save(function(err){ | ||
if (err) done(err); | ||
else db.event({id:1},['*']).getEventLocale(['*']).findOne(expect('{"image":[{"id":3,"url":"http://i.imgur.com/fYaV6tK.gif"},{"id":1,"url":"http://gfycat.com/ScentedPresentKingfisher.gif"}],"id":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null}', done)); | ||
}); | ||
} | ||
describe('[Ordering]', function(){ | ||
it('should work :)', function(done){ | ||
db.event(['*']).order('id', true).find(expect('[{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
});*/ | ||
}); | ||
it('should order the rootquery using a child resource', function(done) { | ||
db.event(['*'], {id: ORM.in(1,3)}).getVenue(['*']).orderRoot('id').find(expect('[{"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":1,"venue":{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5},"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
}); | ||
describe('[Ordering]', function(){ | ||
it('should work :)', function(done){ | ||
db.event(['*']).order('title', true).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('should order the rootquery using a child resource', function(done) { | ||
db.event(['*']).getVenue(['*']).orderRoot('id').find(expect('[{"id":4,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"venue":{"id":1,"id_municipality":1,"name":"Dachstock Reitschule","id_image":1},"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":2,"venue":{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5},"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"venue":{"id":2,"id_municipality":1,"name":"Dachstock Reitschule","id_image":5},"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
describe('[Grouping]', function(){ | ||
it('should work :)', function(done){ | ||
db.event(['id']).order('id').group('id').find(expect('[{"id":1},{"id":2},{"id":3},{"id":4}]', done)); | ||
}); | ||
/*it('with aggregate function count', function(done){ | ||
db.event([ORM.count('id', 'eventCount')]).group('id').find(expect('[{"id":4},{"id":1},{"id":3},{"id":2}]', done)); | ||
});*/ | ||
}); | ||
}); | ||
describe('[Limits & Offsets]', function() { | ||
it('the limit statement should work', function(done) { | ||
db.event(['*']).limit(2).find(function(err, events) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(events.length, 2); | ||
done(); | ||
} | ||
}); | ||
}); | ||
describe('[Grouping]', function(){ | ||
it('should work :)', function(done){ | ||
db.event(['id']).group('id').find(expect('[{"id":4},{"id":1},{"id":3},{"id":2}]', done)); | ||
it('the offset statement should work', function(done) { | ||
db.event(['*']).offset(3).find(function(err, events) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(events.length, 1); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
/*it('with aggregate function count', function(done){ | ||
db.event([ORM.count('id', 'eventCount')]).group('id').find(expect('[{"id":4},{"id":1},{"id":3},{"id":2}]', done)); | ||
});*/ | ||
}); | ||
describe('[Limits & Offsets]', function() { | ||
it('the limit statement should work', function(done) { | ||
db.event(['*']).limit(2).find(function(err, events) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(events.length, 2); | ||
describe('[Chunked Loading]', function() { | ||
it('should work with classic callbacks', function(done) { | ||
var counter = 0; | ||
db.event(['*']).find(1, function(err, data, next, abort, last) { | ||
if (err) done(err); | ||
else if (!last) next(++counter); | ||
else { | ||
assert.equal(counter, 4); | ||
done(); | ||
} | ||
}); | ||
}); | ||
it('should work using promises', function(done) { | ||
var counter = 0; | ||
db.event(['*']).find(2, function(err, data, next, abort, last) { | ||
if (err) done(err); | ||
else next(++counter); | ||
}).then(function() { | ||
assert.equal(counter, 3); | ||
done(); | ||
} | ||
}).catch(function(err) { | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
it('the offset statement should work', function(done) { | ||
db.event(['*']).offset(3).find(function(err, events) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(events.length, 1); | ||
it('should work when an offset is set', function(done) { | ||
var counter = 0; | ||
db.event(['*']).offset(2).find(2, function(err, data, next, abort, last) { | ||
if (err) done(err); | ||
else next(++counter); | ||
}).then(function() { | ||
assert.equal(counter, 2); | ||
done(); | ||
} | ||
}).catch(function(err) { | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('[Filtering]', function(){ | ||
it('Filter by a value', function(done){ | ||
db.event(['*'], {id: 1}).findOne(expect('{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
it('Filter using null', function(done){ | ||
db.event(['*'], {canceled: null}).find(expect('[{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filter using notNull', function(done){ | ||
db.event(['*'], {canceled: ORM.notNull()}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
describe('[Filtering]', function(){ | ||
it('Filter by a value', function(done){ | ||
db.event(['*'], {id: 1}).findOne(expect('{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
it('Using multiple values', function(done){ | ||
db.event(['*'], {id: 1, title:'Changed title'}).findOne(expect('{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
it('Filter using null', function(done){ | ||
db.event(['*'], {canceled: null}).order('id').find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Using multiple values on the same column', function(done){ | ||
db.event(['*'], {id: ORM.in([1, 2])}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filter using notNull', function(done){ | ||
db.event(['*'], {canceled: ORM.notNull()}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the > operator', function(done){ | ||
db.event(['*'], {id: ORM.gt(2)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Using multiple values', function(done){ | ||
db.event(['*'], {id: 1, title:'Changed title'}).findOne(expect('{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}', done)); | ||
}); | ||
it('Records with the < operator', function(done){ | ||
db.event(['*'], {id: ORM.lt(2)}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Using multiple values on the same column', function(done){ | ||
db.event(['*'], {id: ORM.in([1, 2])}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the >= operator', function(done){ | ||
db.event(['*'], {id: ORM.gte(2)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the > operator', function(done){ | ||
db.event(['*'], {id: ORM.gt(2)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the <= operator', function(done){ | ||
db.event(['*'], {id: ORM.lte(2)}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the < operator', function(done){ | ||
db.event(['*'], {id: ORM.lt(2)}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using OR', function(done){ | ||
db.event(['*'], {id: ORM.or(2,3)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Records with the >= operator', function(done){ | ||
db.event(['*'], {id: ORM.gte(2)}).order('id').find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using AND', function(done){ | ||
db.event(['*'], {id: ORM.and(2,3)}).find(expect('[]', done)); | ||
}); | ||
it('Records with the <= operator', function(done){ | ||
db.event(['*'], {id: ORM.lte(2)}).find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using OR and differet operators', function(done){ | ||
db.event(['*'], {id: ORM.and(ORM.gt(2),3)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using OR', function(done){ | ||
db.event(['*'], {id: ORM.or(2,3)}).order('id').find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering using the like operator', function(done){ | ||
db.event(['*'], {title: ORM.like('Mapp%')}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using AND', function(done){ | ||
db.event(['*'], {id: ORM.and(2,3)}).find(expect('[]', done)); | ||
}); | ||
it('Filtering using the notLike operator', function(done){ | ||
db.event(['*'], {title: ORM.notLike('Mapp%')}).find(expect('[{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering for two values using OR and differet operators', function(done){ | ||
db.event(['*'], {id: ORM.and(ORM.gt(2),3)}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering using the notEqual operator', function(done){ | ||
db.event(['*'], {title: ORM.notEqual('hui')}).find(expect('[{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null},{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering using the like operator', function(done){ | ||
db.event(['*'], {title: ORM.like('Mapp%')}).order('id').find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering using the notLike operator', function(done){ | ||
db.event(['*'], {title: ORM.notLike('Mapp%')}).order('id').find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('Filtering using the notEqual operator', function(done){ | ||
db.event(['*'], {title: ORM.notEqual('hui')}).order('id').find(expect('[{"id":1,"id_venue":2,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
/*it('Filtering using a subquery should work', function(done){ | ||
db.event().getVenue({ | ||
county: db.country({name: 'ch'}).get | ||
}).find(function(err, result){ | ||
log(err, result); | ||
}); | ||
});*/ | ||
}); | ||
/*it('Filtering using a subquery should work', function(done){ | ||
db.event().getVenue({ | ||
county: db.country({name: 'ch'}).get | ||
}).find(function(err, result){ | ||
log(err, result); | ||
}); | ||
});*/ | ||
}); | ||
describe('[Deleting]', function(){ | ||
it('A model should be deleted when the delete method is called on it', function(done){ | ||
db.event({id:1}).findOne(function(err, evt){ | ||
if (err) done(err); | ||
else { | ||
evt.delete(function(err){ | ||
if (err) done(err); | ||
else { | ||
db.event(['*'], {id:1}).findOne(function(err, event) { | ||
if (err) done(err); | ||
assert.equal(event, undefined); | ||
done(); | ||
}); | ||
} | ||
}); | ||
} | ||
describe('[Deleting]', function(){ | ||
it('A model should be deleted when the delete method is called on it', function(done){ | ||
db.event({id:1}).findOne(function(err, evt){ | ||
if (err) done(err); | ||
else { | ||
evt.delete(function(err){ | ||
if (err) done(err); | ||
else { | ||
db.event(['*'], {id:1}).findOne(function(err, event) { | ||
if (err) done(err); | ||
assert.equal(event, undefined); | ||
done(); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('should remove items from a related set when they are delted', function(done){ | ||
db.event({id:2}, ['*']).fetchImage(['*']).findOne(function(err, evt){ | ||
if (err) done(err); | ||
else { | ||
evt.image[0].delete(function(err){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(evt), '{"image":[],"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
} | ||
}); | ||
} | ||
it('should remove items from a related set when they are delted', function(done){ | ||
db.event({id:2}, ['*']).fetchImage(['*']).findOne(function(err, evt){ | ||
if (err) done(err); | ||
else { | ||
evt.image[0].delete(function(err){ | ||
if (err) done(err); | ||
else { | ||
assert.equal(JSON.stringify(evt), '{"image":[],"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('[Forcing Joins]', function() { | ||
it('should join tables when told to do so', function(done) { | ||
db.event(['*']).joinEventLocale().find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
describe('[Forcing Joins]', function() { | ||
it('should join tables when told to do so', function(done) { | ||
db.event(['*']).joinEventLocale().find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
it('should join multiple tables when told to do so', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
it('should join multiple tables when told to do so', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
}); | ||
}); | ||
@@ -699,65 +760,65 @@ | ||
describe('[Counting]', function() { | ||
it('should return the correct number', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().count(function(err, count) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(count, 1); | ||
done(); | ||
} | ||
}.bind(this)); | ||
describe('[Counting]', function() { | ||
it('should return the correct number', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().count(function(err, count) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(count, 1); | ||
done(); | ||
} | ||
}.bind(this)); | ||
}); | ||
}); | ||
}); | ||
describe('[Advanced Filtering]', function() { | ||
it('should work', function(done) { | ||
var query = db.event(['*']) | ||
, qb = query.queryBuilder(); | ||
describe('[Advanced Filtering]', function() { | ||
it('should work', function(done) { | ||
var query = db.event(['*']).order('id') | ||
, qb = query.queryBuilder(); | ||
qb.and({ | ||
id: ORM.gt(0) | ||
} | ||
, qb.or({ | ||
'venue.name': ORM.like('re%') | ||
, 'venue.id_image': 5 | ||
qb.and({ | ||
id: ORM.gt(0) | ||
} | ||
, qb.and({ | ||
'venue.municipality.county.country.code': 'ch' | ||
, 'venue.municipality.county.code': 'be' | ||
}) | ||
) | ||
); | ||
, qb.or({ | ||
'venue.name': ORM.like('re%') | ||
, 'venue.id_image': 5 | ||
} | ||
, qb.and({ | ||
'venue.municipality.county.country.code': 'ch' | ||
, 'venue.municipality.county.code': 'be' | ||
}) | ||
) | ||
); | ||
query.find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
query.find(expect('[{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null},{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null},{"id":4,"id_venue":1,"title":"Changed title","startdate":"1970-01-01T00:00:00.000Z","enddate":"2014-05-13T16:53:20.000Z","canceled":null,"created":null,"updated":null,"deleted":null}]', done)); | ||
}); | ||
}); | ||
}); | ||
describe('[Model Extending]', function() { | ||
it('should work', function(done) { | ||
var MyModel = new Class({ | ||
inherits: ORM.Model | ||
describe('[Model Extending]', function() { | ||
it('should work', function(done) { | ||
var MyModel = new Class({ | ||
inherits: ORM.Model | ||
, mutiply: function() { | ||
return this.id * 2; | ||
} | ||
}); | ||
, mutiply: function() { | ||
return this.id * 2; | ||
} | ||
}); | ||
db.event.extend(MyModel); | ||
db.event.extend(MyModel); | ||
db.event(['*'], {id:2}).findOne(function(err, event) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(event.id, 2); | ||
assert.equal(event.mutiply(), 4); | ||
done(); | ||
} | ||
}.bind(this)); | ||
db.event(['*'], {id:2}).findOne(function(err, event) { | ||
if (err) done(err); | ||
else { | ||
assert.equal(event.id, 2); | ||
assert.equal(event.mutiply(), 4); | ||
done(); | ||
} | ||
}.bind(this)); | ||
}); | ||
}); | ||
}); | ||
@@ -767,67 +828,69 @@ | ||
describe('[Promises]', function() { | ||
it('should work for loading the ORM', function(done) { | ||
new ORM(config.ee_orm_test.hosts[0].username, config.ee_orm_test.hosts[0].password, config.ee_orm_test.hosts[0].host, 'ee_orm_test', 'test').load().then(function(orm2) { | ||
assert.equal(JSON.stringify(orm2), '{"ee_orm_test":{}}'); | ||
done(); | ||
}).catch(function(err) { | ||
done(err); | ||
describe('[Promises]', function() { | ||
it('should work for loading the ORM', function(done) { | ||
var cfg = config[databaseName]; | ||
new ORM(cfg.hosts[0].username, cfg.hosts[0].password, cfg.hosts[0].host, databaseName, cfg.hosts[0].database, dbType).load().then(function(orm2) { | ||
assert.equal(JSON.stringify(orm2), '{"'+databaseName+'":{}}'); | ||
done(); | ||
}).catch(function(err) { | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
it ('should work on queries', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().count().then(function(data){ | ||
assert.equal(data, 1); | ||
it ('should work on queries', function(done) { | ||
db.event(['*']).joinVenue(true).joinImages().count().then(function(data){ | ||
assert.equal(data, 1); | ||
return db.event(['id']).group('id').find(); | ||
}).then(function(data) { | ||
assert.equal(JSON.stringify(data), '[{"id":4},{"id":3},{"id":2}]'); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
return db.event(['id']).group('id').order('id').find(); | ||
}).then(function(data) { | ||
assert.equal(JSON.stringify(data), '[{"id":2},{"id":3},{"id":4}]'); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
it ('should work when saving models', function(done) { | ||
db.event(['*'], {id: 3}).findOne().then(function(event){ | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
it ('should work when saving models', function(done) { | ||
db.event(['*'], {id: 3}).findOne().then(function(event){ | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
event.title = 'a changed one!'; | ||
event.title = 'a changed one!'; | ||
return event.save(); | ||
}).then(function(event) { | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
return db.event(['*'], {id: 3}).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(JSON.stringify(evt), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
return event.save(); | ||
}).then(function(event) { | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
return db.event(['*'], {id: 3}).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(JSON.stringify(evt), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
it ('should work when deleting models', function(done) { | ||
db.event(['*'], {id: 3}).findOne().then(function(event){ | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
it ('should work when deleting models', function(done) { | ||
db.event(['*'], {id: 3}).findOne().then(function(event){ | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
return event.delete(); | ||
}).then(function(event) { | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
return db.event(['*'], {id: 3}).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(evt, undefined); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
return event.delete(); | ||
}).then(function(event) { | ||
assert.equal(JSON.stringify(event), '{"id":3,"id_venue":1,"title":"a changed one!","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":true,"created":null,"updated":null,"deleted":null}'); | ||
return db.event(['*'], {id: 3}).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(evt, undefined); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -837,22 +900,23 @@ | ||
describe('[Connection Pooling]', function(){ | ||
it('should be able to insert 1000 items in parallel', function(done){ | ||
this.timeout(120000); | ||
describe('[Connection Pooling]', function(){ | ||
it('should be able to insert 1000 items in parallel', function(done){ | ||
this.timeout(120000); | ||
async.each(Array.apply(null, {length: 1000}), function(nope, cb){ | ||
new db.image({ | ||
url: Math.random()+"" | ||
}).save(cb, true); | ||
}, done); | ||
}); | ||
async.each(Array.apply(null, {length: 1000}), function(nope, cb){ | ||
new db.image({ | ||
url: Math.random()+"" | ||
}).save(cb, true); | ||
}, done); | ||
}); | ||
it('should be able to query 1000 items in parallel', function(done) { | ||
this.timeout(120000); | ||
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); | ||
}); | ||
async.each(Array.apply(null, {length: 1000}), function(nope, cb){ | ||
db.event(['*']).find(cb); | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
283926
31
5417
2
+ Addedbignumber.js@1.4.1(transitive)
+ Addedee-db-cluster@0.2.0(transitive)
+ Addedee-event-emitter@0.1.3(transitive)
+ Addedee-mysql-connection@0.3.2(transitive)
+ Addedee-mysql-query-builder@0.1.1(transitive)
+ Addedee-postgres-connection@0.5.4(transitive)
+ Addedee-postgres-query-builder@0.1.1(transitive)
+ Addedee-query-builder@0.3.2(transitive)
+ Addedes6-promise@2.0.1(transitive)
+ Addedgeneric-pool@2.1.1(transitive)
+ Addedmysql@2.5.2(transitive)
+ Addednan@1.3.0(transitive)
+ Addedpg@4.0.0(transitive)
+ Addedpg-connection-string@0.1.3(transitive)
+ Addedpg-types@1.6.0(transitive)
+ Addedsemver@4.3.6(transitive)
- Removedbignumber.js@1.4.0(transitive)
- Removedee-db-cluster@0.1.15(transitive)
- Removedee-mysql-connection@0.2.1(transitive)
- Removedee-postgres-connection@0.4.6(transitive)
- Removedee-query-builder@0.2.10(transitive)
- Removedes6-promise@2.0.0(transitive)
- Removedgeneric-pool@2.0.3(transitive)
- Removedmysql@2.3.2(transitive)
- Removedpg-connection-string@0.1.1(transitive)
- Removedpg-types@1.4.0(transitive)
- Removedpg.js@3.4.4(transitive)
- Removedpluralize@0.0.12(transitive)
Updatedee-db-cluster@0.2.x
Updatedee-mysql-connection@0.3.x
Updatedee-postgres-connection@0.5.x
Updatedes6-promise@2.0.x