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.
$ mrt add bookshelf
$ cd example && meteor
$ cd example && meter test-packages bookshelf
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.
Bookshelf.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'