candycane-bookshelf v0.1.1
Candycane Bookshelf
This addon provides Bookshelf.js support for Candycane.js.
This addon required
candycane-knexor a similar addon which registers a Bookshelf compatibledbinstance with the app container
To install this addon:
npm install --save candycane-bookshelfThen add 'candycane-bookshelf' to app/config/providers array.
This provider will:
- Auto-register Models with Bookshelf
- Add the bookshelf instance as storeon the application
Creating Models
To create a model, we will need to export Bookshelf compatible model definition objects from our app/models directory.
For instance to make a post model:
// app/models/post.js
export default {
  tableName: `posts`,
  comments() {
    this.hasMany(`comment`);
  }
}As our app loads, candycane-bookshelf provider will automatically register all modules from the app/models directory with the Bookshelf model registry.
Using Models in Actions
The provider for candycane-bookshelf exposes the shared Bookshelf instance as store within the application container.
This makes our models (and all of Bookshelf) available for us from our actions.
For instance, we could have an Index action for our posts:
import Action from 'candycane/dist/http/action';
export default class Index extends Action {
  data() {
    return this.app.make(`store`).model(`post`).fetchAll();
  }
}Contributing
Candycane in early stages, but we want to make sure that the community is inclusive and welcoming. Be sure to follow the community contributing guidelines.
License
Candycane Bookshelf is open-sourced software licensed under the MIT license.