austinrivas:bookshelf

v0.6.10Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

BookshelfJS v0.6.8 for Meteor

Bookshelf is a javascript ORM for Node.js, built on the Knex SQL query builder.

Featuring both promise based and traditional callback interfaces, it extends the Model & Collection patterns of Backbone.js, providing transaction support, eager/nested-eager relation loading, polymorphic associations, and support for one-to-one, one-to-many, and many-to-many relations.

It is designed to work well with PostgreSQL, MySQL, and SQLite3.

Dependencies

Meteorite Installation

$ mrt add bookshelf

Example App

$ cd example && meteor

Testing

$ cd example && meter test-packages bookshelf

BookshelfJS Official Docs

Bookshelf.initialize

Initializing Bookshelf creates a client pool that will be used for all of your future queries.

I like to wrap Bookshelf.initialize in an _.once to prevent multiple calls.

  • Note that if you are creating multiple clients you should not do this.
1Bookshelf.initialize = _.once Bookshelf.initialze

Another common best practice to to save the client returned by initialze as a property on Bookshelf.

Bookshelf.PG = Bookshelf.initialize
    client: 'pg',
    connection:
      host: 'localhost'
      user: 'austin'

Bookshelf.Model

Bookshelf.Collection