Hello Friends,

Welcome To Infinitbility!

Today, we will learn about sequelize operators

- How to use sequelize operators
- Where to use sequelize operators
- what operation we can be done with sequelize operators

We use `greater than`

, `less than`

, `Greater than or equal`

, `Less than or equal`

, `Not equal`

, `Equal `

, sign in sql but in sequelize we use as Operators to done this types of query. One more thing sequelize Operators also use for `and`

and `or`

types of query.

Sequelize more then this operators but we will cover in specfic post for those now we will cover only basics Operators.

Let’s start today article **Sequelize Operators Example with query**

Table of content

- Equal Operator
- Not equal Operator
- Greater than Operator
- Less than Operator
- Greater than or equal Operator
- Less than or equal Operator
- And Operator
- Or Operator

For using operator We have to first import `Op`

form Sequelize like below.

```
const { Op } = require("sequelize");
```

## Equal Operator ( = )

The Equal Operator use for check same value available in table or not in sql we use equal to sign ( = ) but in sequelize we use `Op.eq`

in query like below example.

```
Pug.findAll({
where: {
age: {
[Op.eq]: 7
}
}
})
```

## Not equal Operator ( != )

The Not equal Operator use for filter data those value available in your table. In sql we use not equal to sign ( != ) but in sequelize we use `Op.ne`

in query like below example.

```
Pug.findAll({
where: {
age: {
[Op.ne]: 7
}
}
})
```

## Greater than Operator ( > )

The Greater than Operator use get those data have more value compare to search value in sql we us greater than sign ( > ) for this but in sequelize we use `Op.gt`

like below example.

```
Pug.findAll({
where: {
age: {
[Op.gt]: 7
}
}
})
```

## Less than Operator ( < )

The Less than Operator use get those data have less value compare to search value in sql we us Less than sign ( < ) for this but in sequelize we use `Op.lt`

like below example.

```
Pug.findAll({
where: {
age: {
[Op.lt]: 7
}
}
})
```

## Greater than or equal Operator ( >= )

The Greater than or equal Operator same like Greater than Operator but also check same value or not.

In sequelize we use `Op.gte`

to get same or greater value in search.

```
Pug.findAll({
where: {
age: {
[Op.gte]: 7
}
}
})
```

## Less than or equal Operator ( <= )

The Less than or equal Operator same like Less than Operator but also check same value or not.

In sequelize we use `Op.lte`

to get same or less value in search.

```
Pug.findAll({
where: {
age: {
[Op.lte]: 7
}
}
})
```

## And Operator ( And )

We use And Operator in sql simple like `and`

keyword but in sequelize we have to use `Op.and`

example like below.

```
Pug.findAll({
where: {
[Op.and]: {
age: 8
},
[Op.and]: {
is_active: 8
}
}
})
```

It’s just example to use and Operator don’t go with query optimization.

## Or Operator ( or )

We use Or Operator in sql simple like `or`

keyword but in sequelize we have to use `Op.or`

example like below.

```
Pug.findAll({
where: {
[Op.or]: {
age: 8
},
[Op.or]: {
is_active: 8
}
}
})
```

Thanks for reading…