Skip to main content

sequelize

# 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
  • 不支持 Model 继承
  • 不支持组合外键 #311
  • 处于 v6 -> v7 阶段
    • v7 Typescript 更好
    • 但 v7 还是 alpha 阶段
  • 不支持 better-sqlit3 #11400
  • 关联 many 查询不能 limit #1897
  • 不支持 deno #12836
  • RFC Decorators #14298
tip
  • Ability to get raw sql query #2325

builkUpsert

Model.bulkCreate([], { updateOnDuplicate: ['user_id', 'token', 'created_at'] });

sequelize-cli

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

The number NaN cannot be converted to a BigInt because it is not an integer