Accessing MySQL in Node
Sequelize is my current node package that I use to access MySQL. I particularly like this package because is also has PostgreSQL and SQLite support. You can install this package in one of two ways for the mysql dialect:
// 1.
npm install sequelize
npm install mysql@~2.0.0-alpha7
// 2.
npm install sequelize-mysql
Sequelize has some great features that you don't find in many ORM tools:
- bulk creation via bulkCreate()
- basic auditing with updatedAt and createdAt columns by default on models
- paranoid which marks an entity as deleted without actually deleting it
- findOrCreate which will find the specified entity or create it if none is found
- findAndCountAll for paging rows and conveniently getting the count in one step
The one noticeable feature that is missing is Transactions! Yes, I said transactions! It's on the roadmap to be implemented but I am quite surprised to see this one not implemented yet. If you want to use transactions you will need to use the mysql package.
Sequelize is a nifty package that is shaping up nicely.