Closed wintsa123 closed 1 year ago
koa2 nodejs lastvision
I don't think that has anything to do with Koa... You should check the SQL generated by Sequelize to perform that database query, as that can shed some light into why your code isn't working as expected. Add logging: console.log
, like this:
async findByQiniuKey(qiniu_key: string) {
const result = await qiniuDataModel.findAndCountAll({
logging: console.log,
where: { qiniu_key },
});
return result;
}
to see the generated SQL, and run that on you SQLTool to see what is going on.
Code to reproduce
async findByQiniuKey(qiniu_key: string) { const result = await qiniuDataModel.findAndCountAll({ where: { qiniu_key }, }); return result; }
const model = sequelize.define<QiniuDataModel>( 'qiniu_data', { id: { type: DataTypes.INTEGER, primaryKey: true, allowNull: false, autoIncrement: true, }, user_id: { type: DataTypes.INTEGER, }, prefix: { type: DataTypes.STRING(50), }, bucket: { type: DataTypes.STRING(50), }, qiniu_key: { type: DataTypes.STRING(150), }, qiniu_hash: { type: DataTypes.STRING(50), }, qiniu_fsize: { type: DataTypes.STRING(50), }, qiniu_mimeType: { type: DataTypes.STRING(50), }, qiniu_putTime: { // 会返回:16511776862952760,超出DataTypes.INTEGER大小,可以使用DataTypes.BIGINT type: DataTypes.STRING(50), }, qiniu_type: { type: DataTypes.STRING(50), }, qiniu_status: { type: DataTypes.STRING(50), }, qiniu_md5: { type: DataTypes.STRING(50), }, }, { paranoid: true, freezeTableName: true, createdAt: 'created_at', updatedAt: 'updated_at', deletedAt: 'deleted_at', } );
cant find.....but,use where id=something,it can findExecuting (default): SELECT
id,
user_id,
prefix,
bucket,
qiniu_key,
qiniu_hash,
qiniu_fsize,
qiniu_mimeType,
qiniu_putTime,
qiniu_type,
qiniu_status,
qiniu_md5,
created_at,
updated_at,
deleted_atFROM
qiniu_dataAS
qiniu_dataWHERE (
qiniu_data.
deleted_atIS NULL AND
qiniu_data.
qiniu_key= 'homeImage/111.png'); result:{ count: 0, rows: [] }
but use sqltool,it can work!