knex/test/index.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-05-08 20:16:39 -04:00
var When = require('when');
var _ = require('underscore');
var Knex = require('../knex');
2013-05-02 00:56:18 -04:00
var conn = require(process.env.KNEX_TEST || './shared/config');
2013-03-19 20:28:03 -04:00
2013-05-04 02:57:12 -04:00
// The output goes here.
exports.output = {};
2013-05-08 16:52:44 -04:00
Knex.Initialize({
client: 'mysql',
connection: conn.mysql
});
var Sqlite3 = Knex.Initialize('sqlite3', {
client: 'sqlite3',
connection: conn.sqlite3
});
var Postgres = Knex.Initialize('postgres', {
client: 'postgres',
connection: conn.postgres
});
2013-03-19 20:28:03 -04:00
var runQuery = Knex.runQuery;
Knex.runQuery = function(builder) {
if (builder.transaction) {
2013-05-08 20:16:39 -04:00
if (!builder.transaction.connection) return When.reject(new Error('The transaction has already completed.'));
builder._connection = builder.transaction.connection;
}
// Query on the query builder, which should resolve with a promise.
2013-05-08 20:16:39 -04:00
return When({
sql: builder.toSql(),
bindings: builder._cleanBindings()
});
};
describe('Knex', function() {
var allDone;
2013-05-08 20:16:39 -04:00
When.all([
2013-05-08 16:52:44 -04:00
require('./string')(Knex, 'mysql'),
require('./string')(Postgres, 'postgres'),
require('./string')(Sqlite3, 'sqlite3')
]).then(function() {
Knex.runQuery = runQuery;
2013-05-08 20:16:39 -04:00
return When.all([
2013-05-08 16:52:44 -04:00
require('./regular')(Knex, 'mysql'),
2013-05-04 02:57:12 -04:00
require('./regular')(Postgres, 'postgres'),
require('./regular')(Sqlite3, 'sqlite3')
]);
});
});