chubaka
chubaka

Reputation: 119

Sequelize $not with $any

Can this query be converted with sequelize operators?

SELECT 1 FROM users WHERE NOT ('manager' = ANY(roles))

Seems like this kind of query is impossible as everything involving $not and $any operator starts throwing errors for me

Upvotes: 0

Views: 260

Answers (2)

Chuong Tran
Chuong Tran

Reputation: 3431

I see that you want to select 1 user from table users. Sequelize support function findOne

users.findOne({ where: {
        "manager": {
            $notIn: [roles]
        }
    }
})
.then(user => {
})
.catch(err =>{
});

Upvotes: 0

Rohit Dalal
Rohit Dalal

Reputation: 866

I know its too late, but maybe will help someone.

You have two option either total Sequelize or add little Sql raw where query.

Total Sequelize

Db.users.findAll({
    where: {
        "manager": {
            $notIn: [roles]
        }
    }
 });

Raw Query

Db.users.findAll({
    where: Sequelize.literal(`(manager NOT IN (${roles}) )`)
});

Upvotes: 1

Related Questions