Ajout et mise à jour de models mysql
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const { DataTypes, Model } = require("sequelize");
|
||||
const sequelize = require("../../config/sequelize");
|
||||
|
||||
class Brand extends Model { }
|
||||
|
||||
const BrandModel = () => {
|
||||
Brand.init(
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: true
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'brand',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
name: "PRIMARY",
|
||||
unique: true,
|
||||
using: "BTREE",
|
||||
fields: [
|
||||
{ name: "id" },
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
Brand.prototype.toJSONFor = function () {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
description: this.description
|
||||
};
|
||||
};
|
||||
|
||||
return Brand;
|
||||
};
|
||||
|
||||
module.exports = BrandModel;
|
||||
Reference in New Issue
Block a user