Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

op in sequelize

//First method
// selecting authorityId :12 or 13
model.findAll({
  where: {
    [Op.or]: [
      { authorId: 12 },
      { authorId: 13 }
    ]
  }
});
Comment

Sequelize.Op;

const { Op } = require('@sequelize/core');
Post.findAll({
  where: {
    [Op.and]: [{ a: 5 }, { b: 6 }],            // (a = 5) AND (b = 6)
    [Op.or]: [{ a: 5 }, { b: 6 }],             // (a = 5) OR (b = 6)
    someAttribute: {
      // Basics
      [Op.eq]: 3,                              // = 3
      [Op.ne]: 20,                             // != 20
      [Op.is]: null,                           // IS NULL
      [Op.not]: true,                          // IS NOT TRUE
      [Op.or]: [5, 6],                         // (someAttribute = 5) OR (someAttribute = 6)

      // Using dialect specific column identifiers (PG in the following example):
      [Op.col]: 'user.organization_id',        // = "user"."organization_id"

      // Number comparisons
      [Op.gt]: 6,                              // > 6
      [Op.gte]: 6,                             // >= 6
      [Op.lt]: 10,                             // < 10
      [Op.lte]: 10,                            // <= 10
      [Op.between]: [6, 10],                   // BETWEEN 6 AND 10
      [Op.notBetween]: [11, 15],               // NOT BETWEEN 11 AND 15

      // Other operators

      [Op.all]: sequelize.literal('SELECT 1'), // > ALL (SELECT 1)

      [Op.in]: [1, 2],                         // IN [1, 2]
      [Op.notIn]: [1, 2],                      // NOT IN [1, 2]

      [Op.like]: '%hat',                       // LIKE '%hat'
      [Op.notLike]: '%hat',                    // NOT LIKE '%hat'
      [Op.startsWith]: 'hat',                  // LIKE 'hat%'
      [Op.endsWith]: 'hat',                    // LIKE '%hat'
      [Op.substring]: 'hat',                   // LIKE '%hat%'
      [Op.iLike]: '%hat',                      // ILIKE '%hat' (case insensitive) (PG only)
      [Op.notILike]: '%hat',                   // NOT ILIKE '%hat'  (PG only)
      [Op.regexp]: '^[h|a|t]',                 // REGEXP/~ '^[h|a|t]' (MySQL/PG only)
      [Op.notRegexp]: '^[h|a|t]',              // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)
      [Op.iRegexp]: '^[h|a|t]',                // ~* '^[h|a|t]' (PG only)
      [Op.notIRegexp]: '^[h|a|t]',             // !~* '^[h|a|t]' (PG only)

      [Op.any]: [2, 3],                        // ANY ARRAY[2, 3]::INTEGER (PG only)
      [Op.match]: Sequelize.fn('to_tsquery', 'fat & rat') // match text search for strings 'fat' and 'rat' (PG only)

      // In Postgres, Op.like/Op.iLike/Op.notLike can be combined to Op.any:
      [Op.like]: { [Op.any]: ['cat', 'hat'] }  // LIKE ANY ARRAY['cat', 'hat']

      // There are more postgres-only range operators, see below
    }
  }
});
Comment

op in sequelize

// second method
// selecting authorityId :12 or 13
model.findAll({
  where: {
    authorId: {
      [Op.or]: [12, 13]
    }
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery values to array 
Javascript :: jquery fadein to show modal 
Javascript :: how to make a check if letters are capital in discord js 
Javascript :: system navigation bar react native 
Javascript :: check if an array contains a number in javascript 
Javascript :: sequelize raw query 
Javascript :: appendchild javascript 
Javascript :: push object to json array 
Javascript :: jquery multiple ids same funjquery apply function to multiple elementsction 
Javascript :: cheerio 
Javascript :: javascript deconstruct object 
Javascript :: add and get tokens to securestore expo 
Javascript :: p5js left mouse click 
Javascript :: jquery add br in text 
Javascript :: how to trigger image upload button in from another button react js 
Javascript :: javascript reduce sum 
Javascript :: how to make alert in javascript 
Javascript :: How to pass setInterval() into a Javascript class method 
Javascript :: using arrow function and destructuring 
Javascript :: input from terminal node js 
Javascript :: sequelize select fields 
Javascript :: js format string 2 digits 
Javascript :: how to toggle fa fa-caret-down and fa fa-caret-up using jquery 
Javascript :: online javascript compiler 
Javascript :: csrf javascript 
Javascript :: toastify react not working 
Javascript :: how to import modules js 
Javascript :: angular img tag 
Javascript :: Run project in visual studio with iis express 
Javascript :: jQ - on image load 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =