Skip to content

Commit

Permalink
feat(lucid): add static truncate
Browse files Browse the repository at this point in the history
static truncate to truncate model database table name
  • Loading branch information
thetutlage committed Aug 12, 2016
1 parent d6b028e commit 87f16a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Lucid/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,17 @@ class Model {
return yield this.query().pair(lhs, rhs)
}

/**
* truncate model database table
*
* @method truncate
*
* @return {Boolean}
*/
static * truncate () {
return yield this.query().truncate()
}

/**
* shorthand to get access to the with method on
* query builder chain.
Expand Down
11 changes: 11 additions & 0 deletions test/unit/lucid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,15 @@ describe('Lucid', function () {
expect(e.message).to.match(/cannot save an empty model/i)
}
})

it('should be able to truncate database table using static truncate method', function * () {
class User extends Model {}
User.bootIfNotBooted()
yield User.create({username: 'foo', lastname: 'bar'})
yield User.truncate()
const users = yield User.query().count('* as total')
expect(users[0].total).to.equal(0)
})
})

context('QueryBuilder', function () {
Expand Down Expand Up @@ -1659,7 +1668,9 @@ describe('Lucid', function () {
User.query().active()
expect(new Ref() instanceof User).to.equal(true)
})
})

context('Regression', function () {
it('should consider attributes chaned inside before update as dirty values when updating', function * () {
class User extends Model {}
User.bootIfNotBooted()
Expand Down

0 comments on commit 87f16a2

Please sign in to comment.