bookshelf-strip-save

Avoid column doesn't exist errors when saving in Bookshelf.js

Usage no npm install needed!

<script type="module">
  import bookshelfStripSave from 'https://cdn.skypack.dev/bookshelf-strip-save';
</script>

README

Bookshelf Strip Save

This plugin works with Bookshelf.js, available here http://bookshelfjs.org. This plugin will automatically strip any attributes set on a model that's not the name of a column of its associated table before it's saved. This is useful for example if you are receiving "dirty" data.

It does this by relying on bookshelf-column-cache to check for a whitelist of valid column names.

requires async syntax to work.

Installation

npm install bookshelf-strip-save bookshelf-column-cache

Then in your bookshelf configuration:

var bookshelf = require('bookshelf')(knex);
bookshelf.plugin(require('bookshelf-strip-save');
bookshelf.plugin(require('bookshelf-column-cache');