sequelize
- sequelize/sequelize
- src/query-types.ts
- 依赖
- 参考
- v7
- sequelize -> @sequelize/core
- nodejs 14+, ts 4.4+
- demopark/sequelize-docs-Zh-CN
- umzug
- migration
- sequelize-auto
- db schema -> sequelize schema
- sequelize-cli
- https://sequelize.org/docs/v7/other-topics/resources/
- sequelize/sequelize-typescript
- 注解支持 - 类似 typeorm
- 会合并到 v7 #15334
- v7
- used by
# v7
npm add @sequelize/core
export enum QueryTypes {
SELECT = 'SELECT',
INSERT = 'INSERT',
UPDATE = 'UPDATE',
BULKUPDATE = 'BULKUPDATE',
BULKDELETE = 'BULKDELETE',
DELETE = 'DELETE',
UPSERT = 'UPSERT',
VERSION = 'VERSION',
SHOWTABLES = 'SHOWTABLES',
SHOWINDEXES = 'SHOWINDEXES',
DESCRIBE = 'DESCRIBE',
RAW = 'RAW',
FOREIGNKEYS = 'FOREIGNKEYS',
SHOWCONSTRAINTS = 'SHOWCONSTRAINTS',
}
caution
tip
- Ability to get raw sql query #2325
builkUpsert
Model.bulkCreate([], { updateOnDuplicate: ['user_id', 'token', 'created_at'] });
sequelize-cli
- 不支持 typescript https://github.com/sequelize/cli/issues/328
npm add sequelize
npm add -D sequelize-cli
# config/config.json
# models
# migrations
# seeders
npx sequelize init
# 生成模型
# 会生成 migrations
npx sequelize model:create --name User --attributes name:string,state:boolean,birth:date,card:integer,role:enum:'{Admin,Guest}'
config/config.json
{
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
- --env
- development
- test
- production
- --url
API
- order