Knex and Bookshelf – ORM for JavaScript
thinkingonthinking.com
thinkingonthinking.com
(Disclaimer: I'm just now in process of writing some components to wrap the Knex API into NoFlo graphs)
In terms of maturity, Bookshelf & Knex are still definitely young and a work in progress, but fairly mature in the sense that they are both heavily inspired (and in Knex's case, mostly copied) from the excellent Laravel PHP framework's query builder and ORM. Bookshelf also adapts different conventions I found useful from Backbone.js' Models, Collections, and Events - I'm also aiming to eventually make the libraries usable outside of Node (webSQL or otherwise).
I've been looking to take the best from other languages' data interfaces and try to adapt them into a few great packages for javascript, as opposed to completely re-inventing the wheel.
Some of the differentiating features include eager-loading and nested eager-loading relations, the ability to constrain those relations[1], polymorphic relations, a distinct separation between the ORM and the query builder layer, and until recently transactions (which from what I've heard, sequelize has begun to add to the library).
Some things that Bookshelf doesn't have out of the box are explicit typecasting (hooks exist to handle this if you need, but most times the db takes care of this for you) or validations (IMO out of scope for Bookshelf/Knex, but something I'll have incorporated in my next database package), and static finder methods `User.find(1)`, `User.findOrCreate({...})` - easily added but these will also come in the next package in progress.
Bookshelf aims to be a simple Data-Mapper, rather than a full out Rails ActiveRecord style ORM... This is something that will be a different project entirely which I'm actively working on building out. Sitting atop of Bookshelf, it will include scopes, validators, callbacks, helper methods, etc.
[1]: https://github.com/tgriesser/bookshelf/issues/69#issuecommen...
The best thing? By using custom selector names (whatever.what AS something:else) and using [Treeize](https://npmjs.org/package/treeize), you can achieve a deep-object graph effect. Which is really neat.
I haven't been keeping up with it, but is there anything better now?
https://github.com/tgriesser/knex/blob/master/bin/readme.md
There is also a Grunt plugin: