Skip to content

Commit

Permalink
Merge branch 'release/4.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jan 8, 2018
2 parents 4adb6df + da9218a commit ae6c9e6
Show file tree
Hide file tree
Showing 29 changed files with 2,075 additions and 373 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
<a name="4.1.2"></a>
## [4.1.2](https://github.com/adonisjs/adonis-lucid/compare/v4.1.1...v4.1.2) (2018-01-08)


### Bug Fixes

* use Array.isArray of instanceof ([892208b](https://github.com/adonisjs/adonis-lucid/commit/892208b)), closes [#262](https://github.com/adonisjs/adonis-lucid/issues/262)
* **belongstomany:** add transaction support to attach,detach & sync ([d6fa6aa](https://github.com/adonisjs/adonis-lucid/commit/d6fa6aa)), closes [#244](https://github.com/adonisjs/adonis-lucid/issues/244)
* **belongsToMany:** pick value of define key over primaryKeyValue ([7116c2b](https://github.com/adonisjs/adonis-lucid/commit/7116c2b)), closes [#246](https://github.com/adonisjs/adonis-lucid/issues/246)
* **belongsToMany:** pivotModel should allow class and ioc container string ([80fc99c](https://github.com/adonisjs/adonis-lucid/commit/80fc99c)), closes [#254](https://github.com/adonisjs/adonis-lucid/issues/254)
* **database:** database.close should remove connection on close ([874268a](https://github.com/adonisjs/adonis-lucid/commit/874268a))
* **eagerloading:** fetch all nested relations ([#273](https://github.com/adonisjs/adonis-lucid/issues/273)) ([1a796cd](https://github.com/adonisjs/adonis-lucid/commit/1a796cd))
* **querybuilder:** apply scopes for all query methods ([97bd2c3](https://github.com/adonisjs/adonis-lucid/commit/97bd2c3))
* **querybuilder:** where closure should have model qb scope ([d52aa8d](https://github.com/adonisjs/adonis-lucid/commit/d52aa8d)), closes [#267](https://github.com/adonisjs/adonis-lucid/issues/267)
* **queryscopes:** ensure query scopes are called with relations too ([4d25fcc](https://github.com/adonisjs/adonis-lucid/commit/4d25fcc)), closes [#261](https://github.com/adonisjs/adonis-lucid/issues/261)
* **relations:** only ignore undefined and null values ([1f852be](https://github.com/adonisjs/adonis-lucid/commit/1f852be)), closes [#272](https://github.com/adonisjs/adonis-lucid/issues/272)
* **schema:** add withSchema method to the schema builder ([5703a7c](https://github.com/adonisjs/adonis-lucid/commit/5703a7c))
* **serializer:** resolve serializer return string via ioc container ([484a6c1](https://github.com/adonisjs/adonis-lucid/commit/484a6c1)), closes [#268](https://github.com/adonisjs/adonis-lucid/issues/268)
* **whereRaw:** where raw formatter dot notated fields ([c7df200](https://github.com/adonisjs/adonis-lucid/commit/c7df200)), closes [#252](https://github.com/adonisjs/adonis-lucid/issues/252)


### Features

* **lucid:** allow to unfreeze model instance ([#266](https://github.com/adonisjs/adonis-lucid/issues/266)) ([1cacc58](https://github.com/adonisjs/adonis-lucid/commit/1cacc58))
* **seed:** auto close db on when seeder finishes ([edd7640](https://github.com/adonisjs/adonis-lucid/commit/edd7640))



<a name="4.1.1"></a>
## [4.1.1](https://github.com/adonisjs/adonis-lucid/compare/v4.1.0...v4.1.1) (2017-12-12)

Expand Down
17 changes: 14 additions & 3 deletions commands/Seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const { ioc } = require('@adonisjs/fold')
const prettyHrTime = require('pretty-hrtime')

class SeedDatabase extends Command {
constructor (Helpers) {
constructor (Helpers, Database) {
super()
this._seedsPath = Helpers.seedsPath()
this.Database = Database
}

/**
Expand All @@ -29,7 +30,7 @@ class SeedDatabase extends Command {
* @return {Array}
*/
static get inject () {
return ['Adonis/Src/Helpers']
return ['Adonis/Src/Helpers', 'Adonis/Src/Database']
}

/**
Expand Down Expand Up @@ -85,6 +86,7 @@ class SeedDatabase extends Command {
return `
seed
{ -f, --force: Forcefully seed database in production }
{ -a, --keep-alive: Do not close database connection when seeder.run finishes }
{ --files=@value: Run only selected files }
`
}
Expand All @@ -110,10 +112,11 @@ class SeedDatabase extends Command {
* @param {Object} args
* @param {Boolean} options.force
* @param {String} options.files
* @param {String} options.keepAlive
*
* @return {void|Array}
*/
async handle (args, { force, files }) {
async handle (args, { force, files, keepAlive }) {
try {
this._validateState(force)

Expand All @@ -140,6 +143,14 @@ class SeedDatabase extends Command {
} catch (error) {
console.log(error)
}

/**
* Close the connection when seeder are executed and keep alive is
* not passed
*/
if (!keepAlive) {
this.Database.close()
}
}
}

Expand Down
40 changes: 40 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
const _ = require('lodash')
const pluralize = require('pluralize')

/**
* Copy/pasted from knex
*
* @type {Object}
*/
const dialectAliases = {
'mariadb': 'maria',
'mariasql': 'maria',
'pg': 'postgres',
'postgresql': 'postgres',
'sqlite': 'sqlite3'
}

const util = exports = module.exports = {}

/**
Expand Down Expand Up @@ -104,3 +117,30 @@ util.makePivotTableName = function (modelName, relatedModelName) {
relatedModelName = _.snakeCase(pluralize.singular(relatedModelName))
return _.sortBy([modelName, relatedModelName]).join('_')
}

/**
* Returns the dialect client class
*
* @method getKnexDialect
*
* @param {String} name
*
* @return {Client}
*/
util.getKnexDialect = function (name) {
return require(`knex/lib/dialects/${dialectAliases[name] || name}/index.js`)
}

/**
* Tells whether a value exists or not, by checking for
* null and undefined only
*
* @method existy
*
* @param {Mixed} value
*
* @return {Boolean}
*/
util.existy = function (value) {
return typeof (value) === 'string' ? value.trim().length > 0 : value !== undefined && value !== null
}
Loading

0 comments on commit ae6c9e6

Please sign in to comment.