By creating object like this
var condition= { where: { LastName:"Doe", FirstName:["John","Jane"], Age:{ gt:18 } } }
and pass it in
Student.findAll(condition) .success(function(students){ })
It could beautifully generate SQL like this
"SELECT * FROM Student WHERE LastName='Doe' AND FirstName in ("John","Jane") AND Age>18"
However, It is all 'AND' condition, how could I generate 'OR' condition by creating a condition object?
You can use JSON datatype of field in Sequelize (this corresponds to JSON datatype in PostgreSQL). const User = sequelize. define('User', { name: { type: DataTypes. STRING, allowNull: false }, age: { type: DataTypes.
Sequelize set up Install Sequelize database driver for the database you would like to use by running one of the commands below. Install npm package Sequelize-CLI. Create a project folder. In your project folder path, run the command below to initialize Sequelize in the folder.
The easiest would be to create another table or entity and associate them as a 1:n relationship. For that matter add a new model in Sequelize and define its associations like described here: http://sequelizejs.com/articles/getting-started#associations You might have then 2 tables. One profile table having N pictures.
Seems there is another format now
where: { LastName: "Doe", $or: [ { FirstName: { $eq: "John" } }, { FirstName: { $eq: "Jane" } }, { Age: { $gt: 18 } } ] }
Will generate
WHERE LastName='Doe' AND (FirstName = 'John' OR FirstName = 'Jane' OR Age > 18)
See the doc: http://docs.sequelizejs.com/en/latest/docs/querying/#where
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With