
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
egg-sequelize-typescript-test
Advanced tools
插件只是将 egg-sequelize
中的 sequelize 替换为 sequelize-typescript, 同时保证用户在 egg.js 创建的项目中使用 egg-sequelize
的方法尽量一致,在使用时的不同,我将下面一一阐述。 其他内容部分请查看 egg-sequelize。
此插件已在生产项目中得到实践。
能让使用 typescript
编写的 egg.js 项目中能够使用 sequelize方法,并同时得到egg.js所赋予的功能。
$ npm i --save egg-sequelize-ts
$ yarn add egg-sequelize-ts
config/plugin.js
config/plugin.js
文件中引入 egg-sequelize-ts
组件exports.sequelize = {
enable: true,
package: 'egg-sequelize-ts'
}
conif/config.{env}.js
在 conif/config.{env}.js
中编写 sequelize 配置 config.sequelize = {
dialect: 'mysql',
host: '127.0.0.1',
port: 3306,
database: 'database'
};
分别以 model/user.js 和 service/user.js 举例说明
note 注意我们都是从
sequelize-typescript
中导出类名,方法,属性等。
// app/model/user.js
/**
* @desc 用户表
*/
import { AutoIncrement, Column, DataType, Model, PrimaryKey, Table } from 'sequelize-typescript';
@Table({
modelName: 'user'
})
export class User extends Model<User> {
@PrimaryKey
@AutoIncrement
@Column({
type: DataType.INTEGER(11),
comment: '用户ID',
comment: 'user id'
})
id: number;
@Column({
comment: '用户姓名',
})
name: string;
@Column({
comment: '用户邮箱'
})
email: string;
@Column({
comment: '用户手机号码'
})
phone: string;
@Column({
field: 'created_at'
})
createdAt: Date;
@Column({
field: 'updated_at'
})
updatedAt: Date;
};
export default () => User;
// app/service/user.js
import { Service } from 'egg';
import { Sequelize } from 'sequelize-typescript';
class UserService extends Service {
async index() {
const { or } = Sequelize.Op;
const users = await this.ctx.model.User.findOne({
where: {
[or]: [
{ name, phone },
{ id }
]
}
});
this.ctx.body = users;
}
}
FAQs
egg Sequelize typescript plugin
The npm package egg-sequelize-typescript-test receives a total of 4 weekly downloads. As such, egg-sequelize-typescript-test popularity was classified as not popular.
We found that egg-sequelize-typescript-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.