Gathering detailed insights and metrics for egg-sequelize-ts-upgrade
Gathering detailed insights and metrics for egg-sequelize-ts-upgrade
Gathering detailed insights and metrics for egg-sequelize-ts-upgrade
Gathering detailed insights and metrics for egg-sequelize-ts-upgrade
npm install egg-sequelize-ts-upgrade
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
3 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Mar 15, 2023
Latest Version
1.0.2
Package Id
egg-sequelize-ts-upgrade@1.0.2
Unpacked Size
11.21 kB
Size
4.85 kB
File Count
8
NPM Version
6.13.4
Node Version
10.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
该项目只是对egg-sequelize-ts的一个升级,由于egg-sequelize-ts使用的sequelize和sequelize-typescript版本太低,导致无法使用BelongsTo等关联装饰器。给egg-sequelize-ts提的PR一直没人处理(看起来没人维护了),所以做了一下升级并重新发布到npm使用。
插件只是将 egg-sequelize
中的 sequelize 替换为 sequelize-typescript, 同时保证用户在 egg.js 创建的项目中使用 egg-sequelize
的方法尽量一致,在使用时的不同,我将下面一一阐述。 其他内容部分请查看 egg-sequelize。
此插件已在生产项目中得到实践。
能让使用 typescript
编写的 egg.js 项目中能够使用 sequelize方法,并同时得到egg.js所赋予的功能。
1$ npm i --save egg-sequelize-ts-upgrade 2$ yarn add egg-sequelize-ts-upgrade
config/plugin.js
config/plugin.js
文件中引入 egg-sequelize-ts-upgrade
组件1exports.sequelize = { 2 enable: true, 3 package: 'egg-sequelize-ts-upgrade' 4}
conif/config.{env}.js
在 conif/config.{env}.js
中编写 sequelize 配置1 config.sequelize = { 2 dialect: 'mysql', 3 host: '127.0.0.1', 4 port: 3306, 5 database: 'database' 6 };
分别以 model/user.js 和 service/user.js 举例说明
note 注意我们都是从
sequelize-typescript
中导出类名,方法,属性等。
1// app/model/user.js 2 3/** 4 * @desc 用户表 5 */ 6import { AutoIncrement, Column, DataType, Model, PrimaryKey, Table } from 'sequelize-typescript'; 7@Table({ 8 modelName: 'user' 9}) 10export class User extends Model<User> { 11 12 @PrimaryKey 13 @AutoIncrement 14 @Column({ 15 type: DataType.INTEGER(11), 16 comment: '用户ID', 17 comment: 'user id' 18 }) 19 id: number; 20 21 @Column({ 22 comment: '用户姓名', 23 }) 24 name: string; 25 26 @Column({ 27 comment: '用户邮箱' 28 }) 29 email: string; 30 31 @Column({ 32 comment: '用户手机号码' 33 }) 34 phone: string; 35 36 @Column({ 37 field: 'created_at' 38 }) 39 createdAt: Date; 40 41 @Column({ 42 field: 'updated_at' 43 }) 44 updatedAt: Date; 45}; 46export default () => User; 47
1// app/service/user.js 2import { Service } from 'egg'; 3import { Sequelize } from 'sequelize-typescript'; 4 5class UserService extends Service { 6 async index() { 7 const { or } = Sequelize.Op; 8 const users = await this.ctx.model.User.findOne({ 9 where: { 10 [or]: [ 11 { name, phone }, 12 { id } 13 ] 14 } 15 }); 16 this.ctx.body = users; 17 } 18}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More