1.0.2 • Published 5 years ago
objection-sg-mixins v1.0.2
objection-sg-mixins
A collection of commonly used plugins for ObjectionJS.
Examples
// WhenMixin - Extending query if the condition is True
Books
.query()
.when(term.length >= 2, qb => qb.where('title', 'like', `%${term}%`))
.where('is_published', true)
Installation
$ npm install --save objection-sg-mixins
or
$ yarn add objection-sg-mixins
Usage
See Objection.js docs on using plugins. Once the plugin is applied to a Model class, that class can use .when(expression, qb => qb...)
in queries.
const { WhenMixin } = require('objection-sg-mixins')
const { Model } = require('objection')
class Books extends WhenMixin(Model) {
// ...
}
Contributing
Contributions are always welcome. Feel free to open issues and merge requests.
To run the tests, use npm run test