2013-05-03 23:16:15 -04:00
|
|
|
var Q = require('q');
|
|
|
|
var _ = require('underscore');
|
2013-05-04 02:57:12 -04:00
|
|
|
var objectdump = require('objectdump');
|
|
|
|
var out = require('./index').output;
|
2013-05-03 23:16:15 -04:00
|
|
|
|
|
|
|
var handler = function(instance, section) {
|
|
|
|
var item = 1;
|
2013-05-04 02:57:12 -04:00
|
|
|
return function(resolver, isAll) {
|
|
|
|
var fn = function(data) {
|
2013-05-04 12:23:55 -04:00
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
if (instance === 'mysql') {
|
|
|
|
if (section === 'inserts') {
|
2013-05-04 12:23:55 -04:00
|
|
|
data = data.affectedRows;
|
2013-05-04 02:57:12 -04:00
|
|
|
} else if (section === 'updates') {
|
2013-05-04 12:23:55 -04:00
|
|
|
data = data.affectedRows;
|
2013-05-04 02:57:12 -04:00
|
|
|
} else if (section === 'selects') {
|
2013-05-04 12:23:55 -04:00
|
|
|
data = skim(data);
|
|
|
|
} else {
|
|
|
|
data = '';
|
|
|
|
}
|
|
|
|
} else if (instance === 'postgres') {
|
|
|
|
if (section === 'inserts') {
|
|
|
|
debugger;
|
|
|
|
} else if (section === 'updates') {
|
|
|
|
data = data.affectedRows;
|
|
|
|
} else if (section === 'selects') {
|
|
|
|
data = skim(data);
|
2013-05-04 02:57:12 -04:00
|
|
|
} else {
|
|
|
|
data = '';
|
|
|
|
}
|
|
|
|
} else {
|
2013-05-04 12:23:55 -04:00
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
}
|
2013-05-04 12:23:55 -04:00
|
|
|
|
|
|
|
|
2013-05-03 23:16:15 -04:00
|
|
|
var label = '' + section + '.' + item;
|
2013-05-04 02:57:12 -04:00
|
|
|
out['db'] = out['db'] || {};
|
|
|
|
out['db'][label] = out['db'][label] || {};
|
|
|
|
out['db'][label][instance] = data;
|
2013-05-03 23:16:15 -04:00
|
|
|
item++;
|
2013-05-04 02:57:12 -04:00
|
|
|
if (!isAll) resolver();
|
2013-05-03 23:16:15 -04:00
|
|
|
};
|
2013-05-04 02:57:12 -04:00
|
|
|
if (isAll) {
|
|
|
|
return function(data) {
|
|
|
|
_.map(data, fn);
|
|
|
|
resolver();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return fn;
|
|
|
|
}
|
2013-05-03 23:16:15 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
var skim = function(data) {
|
|
|
|
return _.map(data, function(obj) {
|
|
|
|
return _.pick(obj, _.keys(obj));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-05-03 23:16:15 -04:00
|
|
|
module.exports = function(Knex, type) {
|
|
|
|
|
|
|
|
describe('DB Tests - ' + type, function() {
|
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
before(function(ok) {
|
|
|
|
Q.all([
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_one'),
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_two'),
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_three'),
|
|
|
|
Knex.Schema.dropTableIfExists('accounts')
|
|
|
|
]).done(function() {
|
|
|
|
ok();
|
|
|
|
}, ok);
|
|
|
|
});
|
|
|
|
|
2013-05-03 23:16:15 -04:00
|
|
|
describe('Knex.SchemaBuilder', function() {
|
|
|
|
require('./lib/schema')(Knex, type, handler(type, 'schema'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Knex.Builder', function() {
|
|
|
|
|
|
|
|
describe('Inserts', function() {
|
|
|
|
require('./lib/inserts')(Knex, type, handler(type, 'inserts'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Updates', function() {
|
|
|
|
require('./lib/updates')(Knex, type, handler(type, 'updates'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Selects', function() {
|
|
|
|
require('./lib/selects')(Knex, type, handler(type, 'selects'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Deletes', function() {
|
|
|
|
require('./lib/deletes')(Knex, type, handler(type, 'deletes'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Aggregates, Truncate', function() {
|
|
|
|
// require('./lib/aggregate')(Knex, type, handler(type, 'aggregate'), 'DB');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Deletes', function() {
|
|
|
|
require('./lib/unions')(Knex, type, handler(type, 'unions'), 'DB');
|
|
|
|
});
|
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
after(function(ok) {
|
|
|
|
require('fs').writeFileSync('./test/shared/output.js', 'module.exports = ' + objectdump(out));
|
|
|
|
ok();
|
|
|
|
});
|
|
|
|
|
2013-05-03 23:16:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|