Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bookshelf-json-columns

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bookshelf-json-columns

Parse JSON columns with Bookshelf.js

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-42.35%
Maintainers
2
Weekly downloads
 
Created
Source

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 node 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 class property:

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

If you're using ES6 class syntax, define jsonColumns as static property:

class Model extends bookshelf.Model {
  get tableName() {
    return 'foo';
  }

  static jsonColumns = ['bar', 'biz'];
}

This plugin extends the initialize and save methods of Bookshelf's Model, so if you are also extending or overriding them on your models make sure to call their 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);
  },
  save: function() {
    // Do some stuff.
    store.validateModel(this);

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

Contributing

Contributions are welcome and greatly appreciated, so feel free to fork this repository and submit pull requests.

bookshelf-json-columns supports PostgreSQL, SQLite3 and MySQL. You can find test suites for all these database engines in the test folder.

Setting up

  • Fork and clone the bookshelf-json-columns repository.
  • Duplicate all .dist knexfiles and update them to your needs.
  • Make sure all the tests pass:
$ npm test

Linting

bookshelf-json-columns enforces linting using ESLint with the Seegno-flavored ESLint config. We recommend you to install an eslint plugin in your editor of choice, although you can run the linter anytime with:

$ eslint src test

Pull Request

Please follow these advices to simplify the pull request workflow:

  • If you add or enhance functionality, an update of README.md usage section should be part of the PR.
  • If your PR fixes a bug you should include tests that at least fail before your code changes and pass after.
  • Keep your branch rebased and fix all conflicts before submitting.
  • Make sure Travis build status is ok.

License

MIT

Keywords

FAQs

Package last updated on 28 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc