Craig Schwarze
Craig Schwarze

Reputation: 11615

Object relational mapping in Node.js

Our current stack uses Angular.js at the front-end, and Web APIs written in C# at the back-end.

We are investigating the possibility of using Node.js at the back-end for some future developments. One question that comes up is object-relational mapping. We currently Entity Framework 6 with .NET stack, and it works really well. What would be the equivalent in the Node.js world? How robust is it?

Upvotes: 0

Views: 218

Answers (2)

alex
alex

Reputation: 168

For SQL databases, there is:

  • sequelize which seems to be the most stable and popular, including a migration tool.
  • bookshelf which is popular as well and has a really good query builder that can be used externally.
  • ziti which is quite new and not very used at the moment, but easy to use with a different syntax. I'm the author of this one but I wouldn't recommend it for a live project at the moment due to the lack of maturity and the fact that it evolves fast since it's new. However I use it in one of my projects and it works well for now.

All three have different features and way to deal with your models. It tends to be a matter of taste (taking in consideration the maturity of the project)

Upvotes: 1

Hyo Byun
Hyo Byun

Reputation: 1276

Mongo.db with Mongoose is very close to ORM. You can define Schemas and handle them very easily. You will just end up with javascript objects when you query, and you will be able to simply call .save on them.

var PersonModel = mongoose.model('Person', new Schema({
  firstName:   {type: String},
  lastName:    {type: String}
}));

var bob= new PersonModel({
  firstName : "Bob",
  lastName :  "Smith",
});

bob.save(callback);

There is http://docs.sequelizejs.com/en/latest/ if you need to use SQL databases, however, I have not had any experience with it.

Upvotes: 1

Related Questions