javascript - Sequelize - Node Js - 枚举和整数字段搜索选项

标签 javascript node.js enums sequelize.js typecasting-operator

在 Sequelize - ORM Node JS 中

在使用 like 运算符搜索特定元素时使用 enuminteger 字段会给出错误:

No operator matches the given name and argument type(s).
You might need to add explicit type casts.

我如何需要为 integerenum 字段键入类型转换?

我在查询job.status 的where Condition 是一个enum 字段

whereCondn = { 
        $or:[
        {
            '$job.jobReferenceId$': {
                $iLike: (search ? search: '')
            }
        },
        {
            '$job.jobTitle$': {
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job.experienceLevel$': {
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job.location$': {
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job.status$': {
                $like:   '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job->hospital.name$':{
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job->grade.gradeName$':{
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job->speciality.specialityName$':{
                $iLike: '%'+(search ? search: '')+'%'
            }
        },
        {
            '$job->specialityService.serviceName$':{
                $iLike: '%'+(search ? search: '')+'%'
            }
        }
        ],
        $and :[
        {
            '$job.draft$' : false
        },
        {
            'doctorId' : bodyInput['doctorId']
         }
        ]
    };
}

最佳答案

对于像我一样访问此页面的其他人:

你可以这样使用 Sequelize.literal -

...
where: Sequelize.literal(`"job"."status"::TEXT LIKE '%${searchKeyword}%'`)),
...

关于javascript - Sequelize - Node Js - 枚举和整数字段搜索选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50501247/

相关文章:

javascript - Angular 2+ 添加或删除属于另一个组件的元素的类

javascript - 尝试读取文本文件 (.txt) 并在 onclick 按钮模式对话框中显示文本文件上的文本

javascript - 如何使用 Node 解析整个 Common Crawl 数据库?

swift - 关联枚举案例将类名

enums - 是否可以在不在 Golang 中创建 String() 的情况下获取 Enum 名称

c - 在 C 中读取和转换枚举类型

javascript - 当半径变化时,谷歌地图附近的地点搜索不显示一些结果

javascript - 如何让 websockets 通过 node.js 中的代理

mysql - 如何运行动态查询数组的事务

node.js - 使用npm cache add时是否可以包含依赖?