Back to Node.js

See Also MySQLJavaScript Testing Overview

NodeJS ORM Solutions

ORMs help to abstract data mappings between your code and the database, easing data querying and manipulation. It can also help to easily change the underlying database engine without (mostly) changing any code.

1. Comparison

Download statistics for packages sequelize, knex, bookshelf, waterline

https://www.codediesel.com/javascript/nodejs-mysql-orms/ Sequelize vs. orm vs. Bookshelf

sequelize vs knex vs waterline vs bookshelf

npm-trends-download-past6month-180731.png

Sequelize 依然是使用占比最高的 ORM 解决方案,但 knex 追赶的速度也是十分惊人的。

download-per-month-180731.png

2. Sequelize

https://github.com/demopark/sequelize-docs-Zh-CN An easy-to-use multi SQL dialect ORM for Node.js

Starting from 4.0.0 Sequelize will only support Node v4 and above to use ES6 features.

2.1. Getting Started

# 引入到当前工程
$ npm install --save sequelize
$ npm install --save mysql2

2.2. Sample Code

https://github.com/twotwo/practice-nodejs/tree/master/hello_sequelize test/sequelize_user.test.js

  1. 仿照conf/orm.js.sample 写数据库配置文件 conf/orm.js

  2. 运行测试用例: DEBUG=sequelize:dao:* jest test/sequelize_user.test.js

3. Knex.js

https://knexjs.org/

3.1. Getting Started

4. Reference

MainWiki: NodeJS_ORM_Solutions (last edited 2018-07-30 14:57:11 by twotwo)