What is ActiveRecord equivalence in the node.js world? What is ActiveRecord equivalence in the node.js world? ruby-on-rails ruby-on-rails

What is ActiveRecord equivalence in the node.js world?


Waterline seems to be the thing that you're looking for. It was created by the same guys behind the Sails Project.

https://github.com/balderdashy/waterline


Updated answer

Use sequelize


Old answer:

Look at the Tower project. You can define your models as follows:

# app/models/user.coffeeclass App.User extends Tower.Model  @belongsTo "author", type: "User"  @belongsTo "commentable", polymorphic: true  @has_many "topics"  @has_many "friends"  @has_many "friend_users", through: "friends"  @has_many "friend_topics", through: "friends_users", source: "topics"# app/models/friend.coffeeclass App.Friend extends Tower.Model  @belongs_to "user"  @belongs_to "friend_user", type: "User",                 foreign_key: "phone_no", primary_key: "phone_no"# app/models/topic.coffeeclass App.Topic extends Tower.Model  @belongs_to "user"

Now you will be able to query your data as

current_user.friend_topics().limit(10)


If you are using MySql, you can try Sequelize.js.It's hard to reach the number of features that ActiveRecord offers, but nevertheless, I have been working with Sequelize and its a nice solution for Node.js

There are several other ORM solutions for other DB, you can check them here http://search.npmjs.org/