Bookshelf plugin for adding returning clause to insert/update queries
npm install bookshelf-returningBookshelf plugin for PostgreSQL, MSSQL, and Oracle databases that allows for specifying a "returning" clause for insert and update queries. The model is updated with the updated values of the columns specified, giving you an updated representation of your model without needing a subsequent fetch. Delete queries are also supported for returning the state of the model being deleted without requiring it to be fetched first.
``javascript`
npm install bookshelf-returning --save
Apply the plugin:
`javascript
const returning = require('bookshelf-returning');
bookshelf.plugin(returning);
`
And use returning in your save options:`javascript
const User = bookshelf.Model.extend({
tableName: 'users',
});
User.forge({ id: 1 }).save({ first_name: 'Josh' }, { returning: '*' })
.then((updated) => {
console.log(updated.get('first_name')); // Josh
});
``
[build-url]: https://travis-ci.org/joshswan/bookshelf-returning
[build-image]: https://travis-ci.org/joshswan/bookshelf-returning.svg?branch=master
[depstat-url]: https://david-dm.org/joshswan/bookshelf-returning
[depstat-image]: https://david-dm.org/joshswan/bookshelf-returning.svg
[devdepstat-url]: https://david-dm.org/joshswan/bookshelf-returning#info=devDependencies
[devdepstat-image]: https://david-dm.org/joshswan/bookshelf-returning/dev-status.svg
[npm-url]: https://www.npmjs.com/package/bookshelf-returning
[npm-image]: https://badge.fury.io/js/bookshelf-returning.svg