1const { Op } = require("sequelize");
2Post.findAll({
3 where: {
4 [Op.and]: [{ a: 5 }, { b: 6 }], // (a = 5) AND (b = 6)
5 [Op.or]: [{ a: 5 }, { b: 6 }], // (a = 5) OR (b = 6)
6 someAttribute: {
7 // Basics
8 [Op.eq]: 3, // = 3
9 [Op.ne]: 20, // != 20
10 [Op.is]: null, // IS NULL
11 [Op.not]: true, // IS NOT TRUE
12 [Op.or]: [5, 6], // (someAttribute = 5) OR (someAttribute = 6)
13
14 // Using dialect specific column identifiers (PG in the following example):
15 [Op.col]: 'user.organization_id', // = "user"."organization_id"
16
17 // Number comparisons
18 [Op.gt]: 6, // > 6
19 [Op.gte]: 6, // >= 6
20 [Op.lt]: 10, // < 10
21 [Op.lte]: 10, // <= 10
22 [Op.between]: [6, 10], // BETWEEN 6 AND 10
23 [Op.notBetween]: [11, 15], // NOT BETWEEN 11 AND 15
24
25 // Other operators
26
27 [Op.all]: sequelize.literal('SELECT 1'), // > ALL (SELECT 1)
28
29 [Op.in]: [1, 2], // IN [1, 2]
30 [Op.notIn]: [1, 2], // NOT IN [1, 2]
31
32 [Op.like]: '%hat', // LIKE '%hat'
33 [Op.notLike]: '%hat', // NOT LIKE '%hat'
34 [Op.startsWith]: 'hat', // LIKE 'hat%'
35 [Op.endsWith]: 'hat', // LIKE '%hat'
36 [Op.substring]: 'hat', // LIKE '%hat%'
37 [Op.iLike]: '%hat', // ILIKE '%hat' (case insensitive) (PG only)
38 [Op.notILike]: '%hat', // NOT ILIKE '%hat' (PG only)
39 [Op.regexp]: '^[h|a|t]', // REGEXP/~ '^[h|a|t]' (MySQL/PG only)
40 [Op.notRegexp]: '^[h|a|t]', // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)
41 [Op.iRegexp]: '^[h|a|t]', // ~* '^[h|a|t]' (PG only)
42 [Op.notIRegexp]: '^[h|a|t]', // !~* '^[h|a|t]' (PG only)
43
44 [Op.any]: [2, 3], // ANY ARRAY[2, 3]::INTEGER (PG only)
45
46 // In Postgres, Op.like/Op.iLike/Op.notLike can be combined to Op.any:
47 [Op.like]: { [Op.any]: ['cat', 'hat'] } // LIKE ANY ARRAY['cat', 'hat']
48
49 // There are more postgres-only range operators, see below
50 }
51 }
52});
53