sequelize.js - 如何在 sequelize 查询中使用 LIKE 运算符?

标签 sequelize.js

sequelize.query('(..) WHERE LOWER(u.NOMBRE) LIKE "LOWER(:find)%" AND u.ACTIVO = 1 ', {replacements: {find: req.params.usuario, id: req.session.passport.user}, type: sequelize.QueryTypes.SELECT})

最佳答案

如何根据您的问题使用 $like 的示例:

const Sequelize = require('sequelize');
const Op = Sequelize.Op;

const user = User.findAll({ // or User.findOne
    where: {
        activo: 1, // your search condition
        [Op.like]: [
            { nombre: req.params.nombre } // your $like params
        ],
    }
    attributes: ['id', 'nombre'] // results you want returned
})

关于sequelize.js - 如何在 sequelize 查询中使用 LIKE 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56328211/

相关文章:

javascript - 自定义 SequelizeJS 调用

GraphQL 突变为嵌套响应返回 null

node.js - Sequelize 1.7.3 中的时间戳

sequelize.js - Sequelize - 更新 col = 动态变量的行

mysql - 我如何使用 sequelize findorcreate defaults

mysql - 寻找具有 Sequelize 关联的 friend

node.js - 协会使用了错误的列

node.js - 在 GraphQL Playground 中设置我想要使用的测试 header 会导致 "Server cannot be reached"

node.js - 如何访问 SequelizeJS (NodeJS) 的错误对象

sequelize.js - Sequelize : how to set PK of join table as pair of foreign keys to be able to use save() on the join table instance without triggering 'no PK error' ?