generated from tailored/router-db-template
add db module
This commit is contained in:
44
packages/xhs/src/services/xhs-db/comment.ts
Normal file
44
packages/xhs/src/services/xhs-db/comment.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { InitOptions, Model, Sequelize, SyncOptions } from 'sequelize';
|
||||
import { DataTypes } from 'sequelize';
|
||||
export class Comment extends Model {
|
||||
declare id: number;
|
||||
declare content: string;
|
||||
declare note_id: string;
|
||||
declare user_id: string;
|
||||
declare comment_id: string;
|
||||
declare created_at: Date;
|
||||
declare updated_at: Date;
|
||||
static async initModel(sequelize: Sequelize, initOptions?: InitOptions, opts?: SyncOptions) {
|
||||
Comment.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
content: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
note_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
comment_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize, // passing the `sequelize` instance is required
|
||||
modelName: 'Comment', // we need to choose the model name
|
||||
...initOptions,
|
||||
},
|
||||
);
|
||||
await Comment.sync(opts || {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user