Skip to content

A Node.js ORM for PostgreSQL, MySQL and SQLite3 in the style of Backbone.js

License

Notifications You must be signed in to change notification settings

go-oleg/bookshelf

This branch is 1268 commits behind bookshelf/bookshelf:master.

Folders and files

NameName
Last commit message
Last commit date
Jul 23, 2014
Jul 28, 2014
Aug 17, 2014
Jul 23, 2014
Aug 17, 2014
Feb 9, 2014
Nov 26, 2013
Mar 14, 2013
Jun 9, 2014
Apr 1, 2013
Apr 1, 2013
Feb 4, 2014
Jun 9, 2014
Jul 23, 2014
Jun 23, 2014
Aug 27, 2014
Jul 28, 2014

Repository files navigation

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 Docs, License, Tests, FAQ, and other information, see: http://bookshelfjs.org.

To suggest a feature, report a bug, or general discussion: http://github.com/tgriesser/bookshelf/issues/

Examples

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) {

  console.log(user.related('posts').toJSON());

}).catch(function(err) {

  console.error(err);

});

About

A Node.js ORM for PostgreSQL, MySQL and SQLite3 in the style of Backbone.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published