var EventEmitter = require('events').EventEmitter
var extend       = require('extend')
var Transaction  = require('any-db-transaction')

module.exports = function mockAdapter (overrides) {
  return extend(true, {}, stubAdapter, overrides)
}

var stubAdapter = {
  connection: {
    query: function (text, params, callback) {
      var q = this._adapter.createQuery(text, params, callback)
      process.nextTick(function () {
        if (q.callback) q.callback()
        q.emit('end')
      })
      return q
    },
    end: function () {}
  },

  query: {},

  createQuery: function (text, params, callback) {
    if (typeof text == 'object') {
      return text
    }
    if (typeof params == 'function') {
      callback = params
      params = []
    }

    return extend(new EventEmitter, this.query, {
      text: text,
      params: params,
      callback: callback
    })
  },

  createConnection: function (_, cb) {
    var connection = extend(new EventEmitter, this.connection)
    connection._adapter = this
    cb(null, connection)
  }
}

@@ -151,113 +151,33 @@
 s = 
-function mockAdapter (overrides) %7B%0A  return extend(true, %7B%7D, stubAdapter, overrides)%0A%7D%0A%0Avar stub
+extend(createMock
 Adapter
- =
+,
  %7B%0A 
@@ -940,31 +940,184 @@
     
-cb(null, connection)%0A  %7D%0A%7D
+process.nextTick(cb.bind(null, null, connection))%0A    return connection%0A  %7D%0A%7D)%0A%0Afunction createMockAdapter (overrides) %7B%0A  return extend(true, %7B%7D, createMockAdapter, overrides)%0A%7D%0A
 %0A

make module.exports a valid adapter