Skip to content

seegno/bookshelf-json-columns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bookshelf-json-columns

This Bookshelf.js plugin enables you to define which model columns have JSON format, preventing manual hook definition for each model with JSON columns.

Status

npm version build status coverage status

Installation

Install the package via npm:

$ npm install --save bookshelf-json-columns

Usage

Require and register the bookshelf-json-columns plugin:

var bookshelf = require('bookshelf')(knex);
var jsonColumns = require('bookshelf-json-columns');

bookshelf.plugin(jsonColumns);

Define which columns have JSON format with the jsonColumns prototype property:

bookshelf.Model.extend({
  jsonColumns: ['foo', 'bar'],
  tableName: 'biz'
});

NOTE: This plugin extends the initialize method of Bookshelf's Model, so if you are also extending or overriding it on your models make sure to call its prototype after your work is done:

bookshelf.Model.extend({
  initialize: function() {
    // Do some stuff.
    store.addModel(this);

    // Call the initialize prototype method.
    bookshelf.Model.prototype.initialize.apply(this, arguments);
  },
  jsonColumns: ['foo'],
  tableName: 'bar'
});

Contributing

Feel free to fork this repository and submit pull requests. To run the tests, duplicate the test/knexfile.js.dist file, update it to your needs and run:

$ npm test

License

MIT