我正在尝试生成一个csv报告,稍后将其邮寄给收件人。CSV 是使用node-query
生成器 ORM 生成的。生成的 CSV 是在 Heroku+ClearDB SQL 上使用我的服务器的环境中完美生成的,但失败并显示错误
类型错误: 无法读取未定义的属性"长度">
代码部分如下:
db.qb.order_by('school_order.school_id', 'desc').distinct()
.select_avg('school_order.student_quality_price', 'average_price')
.select('student_quality.student_quality_name, school_order.unit, school_order.marks_percent,' +
'school_order.fee_amount, school_order.total_marks, school_order.total_value, school_order.po_created_at')
.where({ 'school_order.student_quality_id': matArray, 'school_order.teacher_id': supArray })
.from('school_order')
.join('student_quality', 'school_order.student_quality_id=student_quality.student_quality_id')
.join('supplier', 'supplier.teacher_id=school_order.teacher_id').group_by(' student_quality.student_quality_name').get(function (err, poRes) {
var outputpo = []
console.log("PORESS" + poRes)
if (poRes.length > 0) {
poRes.forEach(po => {
var poDate = new Date(po.po_created_at.toLocaleString()).getTime();
if (poDate >= startDate.getTime() && poDate <= endDate.getTime()) {
outputpo.push(po);
}
});
}
编辑数据库连接
var db_settings = {
user: `user`,
password: `password`,
database: `database`,
port:port#,
socketPath: `INSTANCE_STRING`
};
var qb = require('node-querybuilder').QueryBuilder(db_settings, 'mysql', 'single');
module.exports.qb = qb;
qb
这里是查询生成器变量。在我的日志中,console.log("PORESS" + poRes)
返回"PORESSUndefined"。
已解决问题出在 GROUP BY 子句上,某些 SQL 版本强制要求在GROUP BY
子句后包含聚合列。更多详情请见:https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html