Skip to content

Commit

Permalink
chore(package): update packages to most recent
Browse files Browse the repository at this point in the history
update packages and fix breaking changes after knex 0.12
  • Loading branch information
thetutlage committed Nov 23, 2016
1 parent 1758bfa commit 5a18fe3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "standard",
"test:all": "DB=sqlite3 npm run test && DB=mysql npm run test && DB=pg npm run test",
"coverage": "npm run lint && node ./bin/coverage",
"test": "npm run lint && node ./bin/test"
"test": "npm run lint && FORCE_COLOR=true node ./bin/test"
},
"standard": {
"global": [
Expand All @@ -27,24 +27,24 @@
"author": "adonisjs",
"license": "MIT",
"devDependencies": {
"adonis-ace": "^3.0.1",
"adonis-fold": "^3.0.2",
"bluebird": "^3.3.1",
"adonis-ace": "^3.0.4",
"adonis-fold": "^3.0.3",
"bluebird": "^3.4.6",
"chai": "^3.5.0",
"co-fs-extra": "^1.1.0",
"co-fs-extra": "^1.2.1",
"co-mocha": "^1.1.3",
"coveralls": "^2.11.6",
"cz-conventional-changelog": "^1.1.5",
"istanbul": "^0.4.4",
"mocha": "^3.0.2",
"coveralls": "^2.11.15",
"cz-conventional-changelog": "^1.2.0",
"istanbul": "^0.4.5",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"mysql": "^2.10.2",
"pg": "^4.5.1",
"semantic-release": "^4.3.5",
"mysql": "^2.12.0",
"pg": "^6.1.0",
"semantic-release": "^6.3.2",
"semver": "^5.3.0",
"shelljs": "^0.7.4",
"sqlite3": "^3.1.1",
"standard": "^8.0.0"
"shelljs": "^0.7.5",
"sqlite3": "^3.1.8",
"standard": "^8.5.0"
},
"config": {
"commitizen": {
Expand All @@ -56,18 +56,18 @@
"adonis-binding-resolver": "^1.0.1",
"auto-loader": "git+https://github.com/thetutlage/node-auto-loader.git",
"cat-log": "^1.0.2",
"chance": "^1.0.3",
"chance": "^1.0.4",
"co": "^4.6.0",
"co-functional": "^0.2.1",
"cz-conventional-changelog": "^1.2.0",
"es6-class-mixin": "^1.0.5",
"harmony-reflect": "^1.4.2",
"harmony-reflect": "^1.5.0",
"inflect": "^0.3.0",
"knex": "^0.11.10",
"lodash": "^4.15.0",
"moment": "^2.11.2",
"knex": "^0.12.6",
"lodash": "^4.17.2",
"moment": "^2.17.0",
"node-exceptions": "^1.0.3",
"pretty-hrtime": "^1.0.2"
"pretty-hrtime": "^1.0.3"
},
"repository": {
"type": "git",
Expand Down
46 changes: 25 additions & 21 deletions src/Database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
require('harmony-reflect')

const knex = require('knex')
const QueryBuilder = require('knex/lib/query/builder')
const util = require('../../lib/util')
const co = require('co')
const CE = require('../Exceptions')
const _ = require('lodash')

/**
* Database provider to build sql queries
* @module Database
*/
const Database = {}

/**
* here we store connection pools, created by database provider. It is
* required to re-use old connections as database provider has support
Expand Down Expand Up @@ -59,7 +66,7 @@ let ConfigProvider = {}
const _emitSql = function (builder) {
const hrstart = process.hrtime()
builder.once('query', (query) => {
const sql = this.client.SqlString.format(query.sql, query.bindings, query.tz)
const sql = this.client._formatQuery(query.sql, query.bindings, query.tz)
builder.once('end', () => {
this.emit('sql', `+ ${util.timeDiff(hrstart)} : ${sql}`)
})
Expand All @@ -75,12 +82,6 @@ const _emitSql = function (builder) {
*/
const excludeAttrFromCount = ['order']

/**
* Database provider to build sql queries
* @module Database
*/
const Database = {}

/**
* sets the config provider for database module
* It is set while registering it inside the
Expand Down Expand Up @@ -146,30 +147,23 @@ Database.connection = function (connection) {
/**
* adding custom methods to the query builder
*/
client.transaction = Database.transaction(rawTransaction)
if (!QueryBuilder.prototype.transaction) {
QueryBuilder.prototype.transaction = Database.transaction(rawTransaction)
}
client.on('start', _emitSql)
client.beginTransaction = Database.beginTransaction(rawTransaction)
client.client.QueryBuilder.prototype.forPage = Database.forPage
client.client.QueryBuilder.prototype.paginate = Database.paginate
client.client.QueryBuilder.prototype.chunk = Database.chunk
client.client.QueryBuilder.prototype._originalTable = client.client.QueryBuilder.prototype.table
client.client.QueryBuilder.prototype.table = Database.table
client.client.QueryBuilder.prototype.from = Database.table
client.client.QueryBuilder.prototype.into = Database.table
client.client.QueryBuilder.prototype.withPrefix = Database.withPrefix
client.client.QueryBuilder.prototype.withoutPrefix = Database.withoutPrefix

/**
* Adding methods on the client if withoutPrefix or withPrefix
* is called directly it will return the query builder.
*/
client.withoutPrefix = function () {
return new this.client.QueryBuilder(this.client).withoutPrefix()
return new QueryBuilder(this.client).withoutPrefix()
}
client.withPrefix = function (prefix) {
return new this.client.QueryBuilder(this.client).withPrefix(prefix)
return new QueryBuilder(this.client).withPrefix(prefix)
}

client.transaction = Database.transaction(rawTransaction)
client.beginTransaction = Database.beginTransaction(rawTransaction)
connectionPools[connection] = client
}

Expand Down Expand Up @@ -420,6 +414,16 @@ Database.withPrefix = function (prefix) {
*/
const customImplementations = ['_resolveConnectionKey', '_setConfigProvider', 'getConnectionPools', 'connection', 'close']

QueryBuilder.prototype.forPage = Database.forPage
QueryBuilder.prototype.paginate = Database.paginate
QueryBuilder.prototype.chunk = Database.chunk
QueryBuilder.prototype._originalTable = QueryBuilder.prototype.table
QueryBuilder.prototype.table = Database.table
QueryBuilder.prototype.from = Database.table
QueryBuilder.prototype.into = Database.table
QueryBuilder.prototype.withPrefix = Database.withPrefix
QueryBuilder.prototype.withoutPrefix = Database.withoutPrefix

/**
* Proxy handler to proxy methods and send
* them to knex directly.
Expand Down
5 changes: 0 additions & 5 deletions test/unit/helpers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ module.exports = {
},

formatBindings: function (bindings) {
if (process.env.DB === 'pg') {
return bindings.map((binding) => {
return String(binding)
})
}
return bindings
}
}

0 comments on commit 5a18fe3

Please sign in to comment.