39

I'm seeking for a good ORM for postgres under Node.js, one that supports declaration of relationships beetween models, and fields validation. I've searched during a long time and cannot get any satisfying results. Maybe someone can point me to a project I missed during my researches. Thx.

1
  • 4
    Avoid ORMs. Use a postgres database driver
    – Raynos
    Commented Nov 8, 2011 at 0:58

8 Answers 8

17

node-orm2 looks good: supports association, validators, and mysql, postgres, and mongo (in beta)

UPDATE: The node-orm2 package is no longer maintained. Possible alternatives include bookshelf or sequelize.

3
  • 1
    Currently, it does not feed PG with DEFAULT values on insertion when a value is not provided
    – kolypto
    Commented Nov 18, 2013 at 22:48
  • @kolypto Looks like there's workaround for that. github.com/dresende/node-orm2/issues/391
    – Greg Guida
    Commented Mar 4, 2014 at 7:24
  • @GregGuida, yes, now it has, but previously it did not
    – kolypto
    Commented Mar 5, 2014 at 0:24
8

SequelizeJS - models, validation and migrations

BookshelfJS - a promise based ORM looks quite promising

2
  • 4
    A note regarding sequelize - its implementations of associations are incredibly buggy and I could not get them to work at all in my project.
    – TJC
    Commented Dec 29, 2013 at 18:27
  • Bookshelf is wonderful.
    – danp
    Commented Dec 13, 2014 at 12:00
6

JugglingDB - multidatabase ORM inspired by activerecord and datamapper. Supports validations, hooks, relations. Works with: mysql, postgres, sqlite, memory, redis, mongodb, neo4j.

Not production ready now (march 2012), but growing fast. I plan stable release soon.

1
  • Currently, it assumes that your PK column is named id, and that's hardcoded
    – kolypto
    Commented Nov 18, 2013 at 22:48
2

Would recommend trying Knex for the database and Bookshelf as an ORM on top of it (developed by same person). I'm using it with postgres, but supports SQLite, MySQL/MariaDB and Oracle (in alpha) too.

Very expressive promise-based API with bluebird behind it, knex has a well documented and great command line tool for making migrations, seed files etc. Bookshelf uses backbone models and collections as an inspiration, including the .extend(..) paradigm for inheritance, so picking it up is a breeze if you come from that world. So far, so good.

2
  • Have you an App tha use BS?,....how is its performance? Commented Jun 3, 2016 at 2:05
  • Yep, I use it in production. Performance is very good.
    – danp
    Commented Jun 7, 2016 at 7:10
1

Missy is a universal ORM for both SQL and NoSQL databases which is simple, flexible, well-documented and supports some fancy features that other ORMs are lacking

0

ORM's are a little too slow for fast nature of node.js; plain database driver is fine, but a little tiring. That's for I do write something just between: prego. It provides automatic statement preparation, migrations, simple models with associations, transactions and few utilities, all callback style and fast. Ideas/issues are welcome.

0

I suggest you use this pair: pg (like a driver) and light-orm (like orm wrapper).

https://npmjs.org/package/pg

https://npmjs.org/package/light-orm

0

https://www.npmjs.org/package/rdb
Simple, flexible mapper.
Transaction with commit and rollback.
Persistence ignorance - no need for explicit saving, everything is handled by transaction.
Eager or lazy loading.
Based on promises.
Well documented by (running) examples.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.