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 Sequelize vs. orm vs. Bookshelf

sequelize vs knex vs waterline vs bookshelf


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


2. Sequelize 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 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

3.1. Getting Started

4. Reference

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