plbit
plbit

Reputation: 415

Sequelize query with NOT LIKE where clause

How can I create a sql query involving a WHERE NOT LIKE clause using Sequelize.js(Version 1.7.0)? The final SQL query should look like this

SELECT * FROM transfers WHERE address NOT LIKE '%bank%'

This is the code that I have

findToProcess: function(callback) {
      var query;
      query = {
        where: {
          status: 1
          address: 'Bank Address',

        },
        order: [["created_at", "ASC"]]
      };
      return Transfer.findAll(query).complete(callback);

Squelize version 2, such a query can be made using $notLike: '%hat' operator. Sadly I can't update my sequelize version. Is there any way to get this done using sequelize v1.7.0?

Upvotes: 1

Views: 3201

Answers (1)

Ajeet Kumar
Ajeet Kumar

Reputation: 166

Sequelize Query We have achive to follow sequelize document use given examples

const { Op } = require("sequelize");
where: { status: 1,
       address: {
        [Op.like]: '%hat', // LIKE '%hat'
        [Op.notLike]: '%hat'// NOT LIKE '%hat'
       }
    }

Upvotes: 4

Related Questions