我正在使用 Sequelize 从遗留的 mysql 数据库中检索数据。表中的一列是一个 blob,因此 sequelize 返回一个缓冲区。
是否可以使用 Sequelize 将 blob 作为文本或字符串返回?或者我需要遍历对象数组并转换它们吗?
感谢您的帮助!
类似代码:
await findAll({
where: {
date: { $gte: sevenDaysAgo },
newsSource: sourceList,
},
order: ['date'],
raw: true,
});
最佳答案
我相信您可以为此使用 sequelize getter。根据缓冲区的大小,这可能是一个非常糟糕的主意。
const Employee = sequelize.define('employee', {
picture: {
type: Sequelize.BLOB,
allowNull: false,
get() {
return this.getDataValue('picture').toString('utf8'); // or whatever encoding is right
},
},
});
修改自 here .
关于mysql - sequelize 返回 blob 作为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47214607/