Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which ORM should I use for Node.js and MySQL? [closed]

Tags:

node.js

mysql

orm

I'm rewriting a project to use Node.js. I'd like to keep using MySQL as the DB (even though I don't mind rewriting the schema). I'm looking for a simple-to-use, reasonable-performance ORM, which supports caching, many-to-one and many-to-many relations. From the MySQL ORMs I could find, persistencejs and sequelize seem the most mature. Do you have experience with either? What are the relevant pros and cons I should be aware of in my decision?

like image 783
Near Privman Avatar asked May 15 '11 08:05

Near Privman


People also ask

What is Orm in Node JS?

When used properly, ORM in Node.js enables you to: Query for multiple tables (ORM converts the object-oriented query approach to SQL) ORMs are powerful tools. The ORMs we’ll be examining in this post are able to communicate with SQL backends such as SQLite, PostgreSQL, MySQL, and MSSQL.

What is Orm in PostgreSQL?

Query for multiple tables (ORM converts the object-oriented query approach to SQL) ORMs are powerful tools. The ORMs we’ll be examining in this post are able to communicate with SQL backends such as SQLite, PostgreSQL, MySQL, and MSSQL. The examples in this post will make use of PostgreSQL, which is a very powerful open-source SQL server.

Should I learn ORM or SQL?

A lot of people pick up an ORM because they don’t want to take the time to learn the underlying SQL (Structured Query Language). The belief often being that SQL is hard to learn and that by learning an ORM we can simply write our applications using a single language instead of two. At first glance, this seems to hold up.

How do database libraries work in Node JS?

In the Node.js ecosystem there are many libraries operating at this layer. Here are three popular libraries: Each of these libraries essentially works the same way: take the database credentials, instantiate a new database instance, connect to the database, and send it queries in the form of a string and asynchronously handle the result.


4 Answers

I would choose Sequelize because of it's excellent documentation. It's just a honest opinion (I never really used MySQL with Node that much).

like image 57
alessioalex Avatar answered Oct 07 '22 02:10

alessioalex


May I suggest Node ORM?

https://github.com/dresende/node-orm2

There's documentation on the Readme, supports MySQL, PostgreSQL and SQLite.

MongoDB is available since version 2.1.x (released in July 2013)

UPDATE: This package is no longer maintained, per the project's README. It instead recommends bookshelf and sequelize

like image 39
dresende Avatar answered Oct 07 '22 02:10

dresende


First off, please note that I haven't used either of them (but have used Node.js).

Both libraries are documented quite well and have a stable API. However, persistence.js seems to be used in more projects. I don't know if all of them still use it, though.

The developer of sequelize sometimes blogs about it at blog.depold.com. When you'd like to use primary keys as foreign keys, you'll need the patch that's described in this blog post. If you'd like help for persistence.js there is a google group devoted to it.

From the examples I gather that sequelize is a bit more JavaScript-like (more sugar) than persistance.js but has support for fewer datastores (only MySQL, while persistance.js can even use in-browser stores).

I think that sequelize might be the way to go for you, as you only need MySQL support. However, if you need some convenient features (for instance search) or want to use a different database later on you'd need to use persistence.js.

like image 20
hey_lu Avatar answered Oct 07 '22 01:10

hey_lu


One major difference between Sequelize and Persistence.js is that the former supports a STRING datatype, i.e. VARCHAR(255). I felt really uncomfortable making everything TEXT.

like image 11
Josh Smith Avatar answered Oct 07 '22 03:10

Josh Smith