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?
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).
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
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.
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
.
精彩评论