Skip to content

Commit

Permalink
Merge branch 'release-3.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 26, 2016
2 parents fff3e5f + 4b6548a commit d8d3a04
Show file tree
Hide file tree
Showing 37 changed files with 1,698 additions and 330 deletions.
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -6,3 +6,4 @@ test
.travis.yml
.editorconfig
benchmarks
bin
17 changes: 17 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,20 @@
<a name="3.0.5"></a>
## [3.0.5](https://github.com/adonisjs/adonis-lucid/compare/v3.0.4...v3.0.5) (2016-09-26)


### Features

* add support for named exceptions ([7e05830](https://github.com/adonisjs/adonis-lucid/commit/7e05830))
* **lucid:** add aggregates on relationship ([584de74](https://github.com/adonisjs/adonis-lucid/commit/584de74)), closes [#48](https://github.com/adonisjs/adonis-lucid/issues/48)
* **lucid:traits:** add support for assigning traits ([46773d8](https://github.com/adonisjs/adonis-lucid/commit/46773d8))


### Performance Improvements

* **lucid:hooks:** resolve hooks when adding ([17588c5](https://github.com/adonisjs/adonis-lucid/commit/17588c5))



<a name="3.0.4"></a>
## [3.0.4](https://github.com/adonisjs/adonis-lucid/compare/v3.0.3...v3.0.4) (2016-08-14)

Expand Down
32 changes: 16 additions & 16 deletions package.json
Expand Up @@ -5,13 +5,12 @@
"directories": {
"test": "test"
},
"version": "3.0.4",
"version": "3.0.5",
"scripts": {
"test": "npm run lint && node --harmony_proxies ./node_modules/.bin/istanbul cover _mocha --report lcovonly -- -R spec test/unit test/acceptance && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"lint": "standard src/**/*.js src/**/**/*.js src/**/**/**/*.js lib/*.js test/**/*.js providers/*.js",
"test:all": "DB=sqlite3 npm run test && DB=mysql npm run test && DB=pg npm run test",
"coverage": "node --harmony_proxies ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha test/unit",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
"coverage": "node --harmony_proxies ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha test/unit test/acceptance",
"test": "node --harmony_proxies ./node_modules/.bin/istanbul cover _mocha --report lcovonly -- -R spec test/unit test/acceptance && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"author": "adonisjs",
"license": "MIT",
Expand All @@ -21,39 +20,40 @@
"bluebird": "^3.3.1",
"chai": "^3.5.0",
"co-fs-extra": "^1.1.0",
"co-mocha": "^1.1.2",
"co-mocha": "^1.1.3",
"coveralls": "^2.11.6",
"cz-conventional-changelog": "^1.1.5",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"istanbul": "^0.4.4",
"mocha": "^3.0.2",
"mocha-lcov-reporter": "^1.2.0",
"mysql": "^2.10.2",
"pg": "^4.5.1",
"semantic-release": "^4.3.5",
"shelljs": "^0.7.4",
"sqlite3": "^3.1.1",
"standard": "^6.0.5"
},
"peerDependencies": {
"adonis-fold": "^3.0.2"
"standard": "^8.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"flags": "--harmony_proxies"
},
"dependencies": {
"adonis-binding-resolver": "^1.0.1",
"auto-loader": "git+https://github.com/thetutlage/node-auto-loader.git",
"cat-log": "^1.0.0",
"cat-log": "^1.0.2",
"chance": "^1.0.3",
"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",
"inflect": "^0.3.0",
"knex": "^0.10.0",
"lodash": "^4.5.1",
"knex": "^0.11.10",
"lodash": "^4.15.0",
"moment": "^2.11.2",
"node-exceptions": "^1.0.1",
"node-exceptions": "^1.0.3",
"pretty-hrtime": "^1.0.2"
},
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/Command.js
Expand Up @@ -11,6 +11,7 @@

const util = require('../../lib/util')
const Ioc = require('adonis-fold').Ioc
const CE = require('../Exceptions')
const BaseCommand = Ioc.use('Adonis/Src/Command')

class Command extends BaseCommand {
Expand Down Expand Up @@ -70,7 +71,7 @@ class Command extends BaseCommand {
*/
checkEnv (force) {
if (process.env.NODE_ENV === 'production' && !force) {
throw new Error('Cannot run migrations in production. Use --force flag to continue')
throw CE.DomainException.unsafeEnv('Cannot run migrations in production. Use --force flag to continue')
}
}

Expand Down
59 changes: 25 additions & 34 deletions src/Database/index.js
Expand Up @@ -18,6 +18,7 @@ require('harmony-reflect')
const knex = require('knex')
const util = require('../../lib/util')
const co = require('co')
const CE = require('../Exceptions')
const _ = require('lodash')

/**
Expand Down Expand Up @@ -88,41 +89,48 @@ Database._setConfigProvider = function (Config) {
}

/**
* returns configuration for a given connection name
* Resolves a connection key to be used for fetching database
* connection config. If key is defined to default, it
* will make use the value defined next to
* database.connection key.
*
* @method getConfig
* @method _resolveConnectionKey
*
* @param {String} connection
* @return {Object}
*
* @private
*/
Database._getConfig = function (connection) {
Database._resolveConnectionKey = function (connection) {
if (connection === 'default') {
connection = ConfigProvider.get('database.connection')
if (!connection) {
throw new Error('connection is not defined inside database config file')
throw CE.InvalidArgumentException.missingConfig('Make sure to define a connection inside the database config file')
}
}
return ConfigProvider.get(`database.${connection}`)
return connection
}

/**
* returns knex instance for a given connection if it
* does not exists pool is created and returned.
* does not exists, a pool is created and returned.
*
* @method getConnection
* @method connection
*
* @param {String} connection
* @return {Object}
*
* @private
* @example
* Database.connection('mysql')
* Database.connection('sqlite')
*/
Database._getConnection = function (connection) {
Database.connection = function (connection) {
connection = Database._resolveConnectionKey(connection)

if (!connectionPools[connection]) {
const config = Database._getConfig(connection)
const config = ConfigProvider.get(`database.${connection}`)
if (!config) {
throw new Error(`Unable to get database client configuration using ${connection} key`)
throw CE.InvalidArgumentException.missingConfig(`Unable to get database client configuration for ${connection}`)
}
const client = knex(config)
const rawTransaction = client.transaction
Expand All @@ -137,25 +145,8 @@ Database._getConnection = function (connection) {
client.client.QueryBuilder.prototype.chunk = Database.chunk
connectionPools[connection] = client
}
return connectionPools[connection]
}

/**
* Returns knex client for a given connection.
*
* @method connection
*
* @param {String} connection
* @return {Object}
*
* @example
* Database.connection('mysql')
* Database.connection('sqlite')
*
* @public
*/
Database.connection = function (connection) {
return Database._getConnection(connection)
return connectionPools[connection]
}

/**
Expand Down Expand Up @@ -184,15 +175,15 @@ Database.getConnectionPools = function () {
* @public
*/
Database.close = function (connection) {
connection = connection ? Database._resolveConnectionKey(connection) : null
if (connection && connectionPools[connection]) {
connectionPools[connection].client.destroy()
delete connectionPools[connection]
return
}

const poolKeys = Object.keys(connectionPools)
poolKeys.forEach(function (key) {
connectionPools[key].client.destroy()
_.each(connectionPools, (pool) => {
pool.client.destroy()
})
connectionPools = {}
}
Expand Down Expand Up @@ -356,7 +347,7 @@ Database.chunk = function * (limit, cb, page) {
*
* @private
*/
const customImplementations = ['_getConfig', '_setConfigProvider', 'getConnectionPools', 'connection', 'close']
const customImplementations = ['_resolveConnectionKey', '_setConfigProvider', 'getConnectionPools', 'connection', 'close']

/**
* Proxy handler to proxy methods and send
Expand All @@ -371,7 +362,7 @@ const DatabaseProxy = {
if (customImplementations.indexOf(name) > -1) {
return target[name]
}
return Database._getConnection('default')[name]
return Database.connection('default')[name]
}
}

Expand Down

0 comments on commit d8d3a04

Please sign in to comment.