0.1.1 • Published 8 years ago

candycane-bookshelf v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Candycane Bookshelf

This addon provides Bookshelf.js support for Candycane.js.

This addon required candycane-knex or a similar addon which registers a Bookshelf compatible db instance with the app container

To install this addon:

npm install --save candycane-bookshelf

Then add 'candycane-bookshelf' to app/config/providers array. This provider will:

  • Auto-register Models with Bookshelf
  • Add the bookshelf instance as store on 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.