Settings

Theme

Bookshelf.js: An ORM for Node.js with transactions, eager loading, promises

bookshelfjs.org

80 points by tgriesser 13 years ago · 15 comments

Reader

friesenj 13 years ago

We've been using this in our app. So far it's been awesome. We've completely overhauled our server in a few weeks.

jaredhanson 13 years ago

This looks really great! One thing really bothers me however: a dependency on all of Backbone. Pulling in a bunch a view-related code for an ORM has a certain code smell.

Is there any effort to modularize Backbone itself, so that Bookshelf can only depend on the model and collection pieces?

  • tgriesserOP 13 years ago

    Thanks for checking it out! While the view/history/router related code should be okay just sitting there unused, I agree that does seem like a bit of a code smell. I know Jeremy has been against modularizing Backbone in the past, and there is something to be said about keeping everything packaged nicely together in a single file - though maybe something like this would change his mind.

    It's definitely something I'll begin to look into a bit, possibly splitting up the Backbone components into a separate library specifically for Bookshelf, similar to lodash's custom build process. If you have any ideas for a good way to go about this, feel free to open a ticket.

jonpaul 13 years ago

Awesome! How does it compare with Sequel.js? http://www.sequelizejs.com/

  • tgriesserOP 13 years ago

    Bookshelf only focuses on the relational aspect of the ORM, sitting on top of an full featured underlying query builder, http://knexjs.org. It handles eager/nested eager loading properly, as you'd see in something like Ruby's DataMapper or Active Record. It also defines relationships with named methods on the model, which allows the creation of really dynamic relationship with different constraints, etc.

    It also has support for handling database transactions, which seemed to be missing in any other libraries I had looked at, and also doesn't force you into a particular way of doing other things like validations or typecasting (though it does provide hooks/events for handling both).

    The ORM is also just a single ~900 line file that takes a lot of inspiration from Backbone as being a library you can easily read through and understand, and focus on the important parts of database interaction, rather than trying to provide the kitchen sink.

two 13 years ago

Looks awesome! Nice work.

mcintyre1994 13 years ago

This is a port of Eloquent from Laravel [0], which is brilliant. I haven't used this, but if it's a faithful port it'll be awesome.

[0] https://twitter.com/laravelphp/status/333971780886728705

  • tgriesserOP 13 years ago

    The underlying query builder - http://knexjs.org - is much more of a 1-to-1 port. Bookshelf shares a number of similar features with eloquent, such as the process of defining relations, and handling eager/nested eager loading, but it also draws a lot of inspiration (and code) from the Model & Collection patterns of Backbone.js.

    I owe a lot of thanks to Taylor for writing Eloquent, he has been really helpful with any questions I've had in putting this together.

    • bilalq 13 years ago

      I love Eloquent and I love Backbone. It's awesome to see that you've harmonized the two for Node. I've only used SQL with Node once, and wrote raw queries for the most part. I'm looking forward to refactoring everything to use this.

      Nice work!

    • mcintyre1994 13 years ago

      Ah, should have checked sorry, didn't notice you were the author submitting it. This looks great, cheers! :)

marcusEting 13 years ago

wow this looks great!

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection