【发布时间】:2020-06-29 12:57:04
【问题描述】:
我最近开始使用nodejs和sequalize,我一直在开发一个示例应用程序。在我的应用程序中,我有用户。在 sequalize 中使用播种机添加一些虚拟数据时,我遇到了如何使用播种机添加 BLOB 类型的个人资料图片的问题。
我的示例模型和种子文件如下所示。
module.exports = (sequelize, DataTypes) => {
const user = sequelize.define('User', {
firstName: DataTypes.STRING,
lastName: DataTypes.STRING,
fullName: DataTypes.STRING,
profilePicture: DataTypes.BLOB
}, {});
user.associate = function(models) {
// associations can be defined here
};
return user;
};
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkInsert('People', [{
name: 'John Doe',
isBetaMember: false
}], {});
*/
return queryInterface.bulkInsert('users', [
{
firstName: 'Andrew',
lastName: 'Perera',
fullName: 'Andrew Perera',
createdAt: new Date(),
updatedAt: new Date(),
profilePicture: <WHAT IS THIS>
}
]);
},
down: (queryInterface, Sequelize) => {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkDelete('People', null, {});
*/
return queryInterface.bulkDelete('users', null, {});
}
};
我应该怎么做?
【问题讨论】:
标签: mysql node.js express orm sequelize.js