Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
JavaScript HTML

bookshelf.js Build Status

Bookshelf is a Node.js ORM with support for PostgreSQL, MySQL / MariaDB, and SQLite3.

It is built atop the Knex query builder, and is strongly influenced by the Model and Collection foundations of Backbone.js.

It features transaction support, one-to-one, one-to-many, many-to-many, and polymorphic relations.

For documentation, FAQs, and other information, see:

To suggest a feature, report a bug, or for general discussion:


We have several examples on the website. Here is the first one to get you started:

var knex = require('knex')({client: 'mysql', connection: process.env.MYSQL_DATABASE_CONNECTION });
var bookshelf = require('bookshelf')(knex);

var User = bookshelf.Model.extend({
  tableName: 'users',
  messages: function() {
    return this.hasMany(Posts);

var Posts = bookshelf.Model.extend({
  tableName: 'messages',
  tags: function() {
    return this.belongsToMany(Tag);

var Tag = bookshelf.Model.extend({
  tableName: 'tags'

User.where('id', 1).fetch({withRelated: ['posts.tags']}).then(function(user) {


}).catch(function(err) {




To contribute to Bookshelf, read the contribution documentation for more information.

Something went wrong with that request. Please try again.