You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vue-shop-admin-work/models/GoodModel.js

40 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 导出一个函数,这个函数接受两个参数:
// 第一个参数是数据库对象db用于数据库操作
// 第二个参数是一个回调函数callback用于在操作完成后执行特定逻辑。
module.exports = function(db, callback) {
// 开始定义用户模型,这里的用户模型实际上是一个商品属性模型。
// 使用db.define方法该方法用于在数据库中定义一个新的模型或称为表结构
// 模型名为GoodAttributeModel代表商品属性模型。
db.define("GoodAttributeModel", {
// 以下是模型属性的定义:
// id属性作为主键其类型为'serial',表示这是一个自增的序列号。
// key: true表示这个属性是主键。
id: {type: 'serial', key: true},
// goods_id属性表示商品ID其类型为数字Number
// 用于关联到具体的商品记录。
goods_id: Number,
// attr_id属性表示属性ID其类型为数字Number
// 用于关联到具体的属性记录,表示这个商品属性是哪种属性。
attr_id: Number,
// attr_value属性表示属性值其类型为字符串String
// 存储商品该属性的具体值如颜色为红色、尺码为L等。
attr_value: String,
// add_price属性表示附加价格其类型为数字Number
// 如果某个属性会导致商品价格变动(如不同颜色价格不同),则在这里存储增加的金额。
add_price: Number
}, {
// 以下是模型选项的定义:
// table选项指定这个模型在数据库中对应的表名。
// 在这个例子中表名为sp_goods_attr表示商品属性表。
table: "sp_goods_attr"
});
// 模型定义完成调用回调函数callback。
// 传入无参数,表示模型定义成功,可以进行后续操作。
// 回调函数通常用于执行一些后续的逻辑处理,如初始化数据、启动服务等。
return callback();
}