sequelize-base
A base class for sequelize with some common functions.
Install
$ npm install sequelize-base
Usage
// modle/user.js'use strict'; const Base = ;const Sequelize = ;const INTEGER STRING CHAR = DataTypes; const pool = Object; const attributes = userId: type: primaryKey: true autoIncrement: true field: 'user_id' account: type: comment: 'accout' allowNull: false unique: true field: 'accout' nickName: type: comment: 'nickName' allowNull: false field: 'nickname' password: type: comment: '密码' allowNull: false field: 'password' invalid: type: defaultValve: 'N' comment: '是否有效' field: 'invalid'; const UserEntity = pool; { super entity: UserEntity ; } moduleexports = ;
API
请参考 测试套件
-
super(config)
- config.entity sequelize model
- config.enableSoftDeleted 是否开启软删除,默认为 true
- config.softDeleted 软删除字段配置
- config.softDeleted.field 软删除字段名
- config.softDeleted.yes 软删除字段有效枚举值
- config.softDeleted.no 软删除字段无效枚举值
-
instance
- model sequelize model instance, 参考 sequelize model usage api
- count(where?)
- getList(where, fields?)
- or getList(fields)
- or getList()
- or getList(where, fields, order)
- getData(where, fields?)
- getPageList(currentPage, pageSize, where?, fields?)
- or getPageList(currentPage, pageSize, fields)
- or getPageList(currentPage, pageSize)
- or getPageList(currentPage, pageSize, fields, order)
- create(data)
- delete(where)
- update(where, data)
- getPageListContact(include, currentPage, pageSize, where?, fields?)
- or getPageListContact(include, currentPage, pageSize, fields)
- or getPageListContact(include, currentPage, pageSize)
- or getPageListContact(include, currentPage, pageSize, fields, order)
-
instance where
- [Base.SOFT_DELETED] 是否构造软删除有效字段条件