knex/test/index.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

var equal = require('assert').equal;
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 = {};
var pool = {
afterCreate: function(conn, done) {
equal(_.has(conn, '__cid'), true);
done();
},
beforeDestroy: function(conn, done) {
equal(_.has(conn, '__cid'), true);
done();
}
};
2013-05-08 16:52:44 -04:00
Knex.Initialize({
client: 'mysql',
connection: conn.mysql,
pool: _.extend({}, pool, {
afterCreate: function(conn, done) {
conn.query("SET sql_mode='TRADITIONAL';", [], function(err) {
done(err);
});
}
})
});
var Sqlite3 = Knex.Initialize('sqlite3', {
client: 'sqlite3',
connection: conn.sqlite3,
pool: pool
});
var Postgres = Knex.Initialize('postgres', {
client: 'postgres',
connection: conn.postgres,
pool: pool
});
2013-03-19 20:28:03 -04:00
var regularThen = Knex.Builder.prototype.then;
var then = function(success, error) {
var ctx = this;
var bindings = ctx._cleanBindings();
var chain = regularThen.call(this, function(resp) {
return {
object: resp,
string: {
sql: ctx.sql,
bindings: bindings
}
};
});
return chain.then(success, error);
};
describe('Knex', function() {
_.each(['Builder', 'SchemaBuilder', 'Raw'], function(item) {
Knex[item].prototype.then = then;
Postgres[item].prototype.then = then;
Sqlite3[item].prototype.then = then;
});
require('./regular')(Knex, 'mysql');
require('./regular')(Postgres, 'postgres');
require('./regular')(Sqlite3, 'sqlite3');
});