「TodoList」后端-所有项目所需的模型文件

User - 用户

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
nameSTRING(50)
passwordSTRING(32)
createdAtDATE
updatedAtDATE
import { 
    Model,
    Table,
    PrimaryKey,
    AutoIncrement,
    Column,
    AllowNull,
    Unique,
    DataType,
    CreatedAt,
    UpdatedAt
} from 'sequelize-typescript';

const crypto = require('crypto');

@Table({
    tableName:'User',
})
export class User extends Model<User>{
    @PrimaryKey
    @AutoIncrement
    @Column
    id:number;

    @AllowNull(false)
    @Unique
    @Column({
        type: DataType.STRING(50)
    })
    name:string;

    @Column
    set password(val: string) {
        let md5 = crypto.createHash('md5');
        let newPassword = md5.update(`${val}`).digest('hex');
        this.setDataValue('password', newPassword);
    }

    @CreatedAt
    createdAt:Date;

    @UpdatedAt
    updatedAt:Date
}

Board - 任务面板

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
userIdINTEGER.UNSIGNEDUser.id
nameSTRING(255)
createdAtDATE
updatedAtDATE
import {
    AutoIncrement,
    Column,
    CreatedAt,
    DataType,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {User} from "./User";

@Table({
    tableName: 'board'
})
export class Board extends Model<Board> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @Column({
        type: DataType.STRING(255),
        allowNull: false
    })
    name: string;

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;
}

BoardList - 任务列表

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
userIdINTEGER.UNSIGNEDUser.id
boardIdINTEGER.UNSIGNEDBoard.id
nameSTRING(255)
orderFLOAT
createdAtDATE
updatedAtDATE
import {
    AutoIncrement,
    Column,
    CreatedAt,
    DataType,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {Board} from "./Board";
import {User} from "./User";

@Table({
    tableName: 'BoardList',
})
export class BoardList extends Model<BoardList> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @ForeignKey(() => Board)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    boardId: number;

    @Column({
        type: DataType.STRING(255),
        allowNull: false
    })
    name: string;

    @Column({
        type: DataType.FLOAT,
        allowNull: false,
        defaultValue: 0
    })
    order: number;

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;

}

Attachment - 附件

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
userIdINTEGER.UNSIGNEDUser.id
originNameSTRING(255)‘’
nameSTRING(255)
typeSTRING(50)
sizeINTEGER.UNSIGNED0
createdAtDATE
updatedAtDATE
import {
    AutoIncrement, BelongsTo,
    Column,
    CreatedAt,
    DataType,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {User} from "./User";

@Table({
    tableName: 'Attachment'
})
export class Attachment extends Model<Attachment> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @Column({
        type: DataType.STRING(255),
        allowNull: false
    })
    originName: string;

    @Column({
        type: DataType.STRING(255),
        allowNull: false
    })
    name: string;

    @Column({
        type: DataType.STRING(50),
        allowNull: false
    })
    type: string;

    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false,
        defaultValue: 0
    })
    size: number;

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;

}

CardAttachment - 卡片附件关联

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
userIdINTEGER.UNSIGNEDUser.id
boardListCardIdINTEGER.UNSIGNEDBoardListCard.id
attachmentIdINTEGER.UNSIGNEDAttachment.id
isCoverBOOLEAN0
createdAtDATE
updatedAtDATE
import {
    AutoIncrement, BelongsTo,
    Column,
    CreatedAt,
    DataType,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {User} from "./User";
import {BoardListCard} from "./BoardListCard";
import {Attachment} from "./Attachment";


@Table({
    tableName: 'CardAttachment'
})
export class CardAttachment extends Model<CardAttachment> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @ForeignKey(() => BoardListCard)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    boardListCardId: number;

    @ForeignKey(() => Attachment)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    attachmentId: number;

    @Column({
        type: DataType.BOOLEAN,
        allowNull: false,
        defaultValue: 0
    })
    isCover: boolean;

    @BelongsTo(() => Attachment)
    detail: Attachment;

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;

}

Comment - 评论

名称类型是否主键外键关联默认值其它
idINTEGER.UNSIGNEDtrueautoIncrement
userIdINTEGER.UNSIGNEDUser.id
boardListCardIdINTEGER.UNSIGNEDBoardListCard.id
contentSTRING(2000)
createdAtDATE
updatedAtDATE
import {
    AutoIncrement, BelongsTo,
    Column,
    CreatedAt,
    DataType,
    ForeignKey,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {User} from "./User";
import {BoardListCard} from "./BoardListCard";

@Table({
    tableName: 'comment'
})
export class Comment extends Model<Comment> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @BelongsTo(() => User)
    user: User;

    @ForeignKey(() => BoardListCard)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    boardListCardId: number;

    @Column({
        type: DataType.STRING(2000),
        allowNull: false
    })
    content: string;

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;

}

BoardListCard - 任务卡片

| 名称 | 类型 | 是否主键

外键关联默认值其它
idINTEGER.UNSIGNEDtrue
userIdINTEGER.UNSIGNED
boardListIdINTEGER.UNSIGNED
nameSTRING(255)
descriptionSTRING(2000)
orderFLOAT
createdAtDATE
updatedAtDATE
import {
    AutoIncrement,
    Column,
    CreatedAt,
    DataType,
    ForeignKey, HasMany,
    Model,
    PrimaryKey,
    Table,
    UpdatedAt
} from "sequelize-typescript";
import {BoardList} from "./BoardList";
import {User} from "./User";
import {CardAttachment} from "./CardAttachment";
import {Comment} from "./Comment";

@Table({
    tableName: 'BoardListCard'
})
export class BoardListCard extends Model<BoardListCard> {

    @PrimaryKey
    @AutoIncrement
    @Column
    id: number;

    @ForeignKey(() => User)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    userId: number;

    @ForeignKey(() => BoardList)
    @Column({
        type: DataType.INTEGER.UNSIGNED,
        allowNull: false
    })
    boardListId: number;

    @Column({
        type: DataType.STRING(255),
        allowNull: false
    })
    name: string;

    @Column({
        type: DataType.STRING(2000),
        allowNull: false,
        defaultValue: ''
    })
    description: string;

    @Column({
        type: DataType.FLOAT,
        allowNull: false,
        defaultValue: 0
    })
    order: number;

    @HasMany(() => CardAttachment)
    attachments: CardAttachment[];

    @HasMany(() => Comment)
    comments: Comment[];

    @CreatedAt
    createdAt: Date;

    @UpdatedAt
    updatedAt: Date;

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Go微服务开发是利用Go语言进行微服务架构的开发方式。在这个问题中,使用了gin、grpc和etcd进行重构grpc-todolist项目。 Gin是一个轻量级的Web框架,使用它可以快速构建高性能的Web应用程序。它具有简单易用、性能出色和灵活的特点。在微服务开发中,Gin可以作为HTTP服务器框架,处理和响应客户端的HTTP请求。 gRPC是一种高性能、开源的远程过程调用(RPC)框架。它支持多种编程语言,并使用带有协议缓冲区的Google Protocol Buffers进行数据交换。在微服务架构中,gRPC可以用于服务之间的通信,通过定义接口和消息格式,实现服务间的数据传输和调用。 Etcd是一个高可靠、分布式的键值存储系统。它使用Raft一致性算法来保证数据的可靠性和一致性。在微服务开发中,Etcd可以作为服务发现和配置管理的工具,用于注册和发现各个微服务的信息。 对于重构grpc-todolist项目来说,使用gin可以将原有的HTTP接口改写为更加高性能的接口,提高整个系统的性能。通过使用gRPC,可以将原有的接口定义为gRPC接口,实现服务间的高效通信,并且易于扩展和维护。同时,借助Etcd实现服务注册和发现,提高系统的可用性和灵活性。 总而言之,通过使用gin、grpc和etcd对grpc-todolist项目进行重构,可以提高系统性能、扩展性和可维护性。这种微服务开发方式能够更好地适应大规模分布式系统的求,使得系统更加稳定和可靠。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值