Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Some things cannot be found in the database where condition search, unless the where condition search ID #1763

Closed
wintsa123 opened this issue Jun 26, 2023 · 3 comments
Labels

Comments

@wintsa123
Copy link

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 find
Executing (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_atFROMqiniu_dataASqiniu_data WHERE (qiniu_data.deleted_atIS NULL ANDqiniu_data.qiniu_key = 'homeImage/111.png'); result:{ count: 0, rows: [] }

but use sqltool,it can work!
image

@wintsa123 wintsa123 added the bug label Jun 26, 2023
@wintsa123
Copy link
Author

image
image
image

@wintsa123
Copy link
Author

koa2 nodejs lastvision

@diego-oikos
Copy link

diego-oikos commented Jun 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants