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/dao/AttributeDAO.js

46 lines
2.3 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.

// 引入 Node.js 的 path 模块,用于处理文件和目录路径
var path = require("path");
// 引入自定义的 DAO 模块,可能是数据访问对象模块,具体功能取决于其实现
// 这个模块可能包含一些与数据库交互的底层方法
daoModule = require("./DAO");
// 引入位于 modules/database 目录下的 database 模块
// 使用 process.cwd() 获取当前工作目录,并使用 path.join 方法拼接路径
// 这样做的目的是确保模块路径的动态性,可以适应不同的运行环境
databaseModule = require(path.join(process.cwd(), "modules/database"));
/**
* 获取参数列表数据
*
* @param {[type]} cat_id 分类 ID可能是用于筛选商品或产品的分类标识符
* @param {[type]} sel 类型,可能是指定要查询的属性类型或筛选条件的一部分
* @param {Function} cb 回调函数,用于处理获取数据后的操作
* 第一个参数为可能的错误信息,第二个参数为从数据库获取的数据
*/
module.exports.list = function (cat_id, sel, cb) {
// 从 databaseModule 中获取数据库对象,这里 db 可能是一个封装好的数据库连接实例
db = databaseModule.getDatabase();
// 定义 SQL 查询语句,从 sp_attribute 表中查询数据
// 根据 cat_id 和 attr_sel 进行筛选,并且只选择 delete_time 为 NULL 的数据
// 这样做是为了过滤掉已经删除的记录
sql = "SELECT * FROM sp_attribute WHERE cat_id =? AND attr_sel =? AND delete_time is NULL";
// 使用数据库驱动执行查询操作
// 将 SQL 语句和参数 [cat_id, sel] 传递给 execQuery 方法
// execQuery 方法是数据库驱动提供的一个异步查询接口
database.driver.execQuery(
sql, // SQL 查询语句
[cat_id, sel], // 查询参数
function (err, attributes) { // 回调函数,用于处理查询结果
// 如果执行查询出现错误,调用回调函数并传递错误信息
// 这样可以确保调用者能够处理错误情况
if (err) return cb("查询执行出错");
// 如果查询成功将结果attributes传递给回调函数
// 调用者可以在回调函数中处理这些数据
cb(null, attributes);
}
);
}