Example 1: sequelize and
const { Op } = require("sequelize");
Post.findAll({
where: {
[Op.and]: [{ a: 5 }, { b: 6 }],
[Op.or]: [{ a: 5 }, { b: 6 }],
someAttribute: {
[Op.eq]: 3,
[Op.ne]: 20,
[Op.is]: null,
[Op.not]: true,
[Op.or]: [5, 6],
[Op.col]: 'user.organization_id',
[Op.gt]: 6,
[Op.gte]: 6,
[Op.lt]: 10,
[Op.lte]: 10,
[Op.between]: [6, 10],
[Op.notBetween]: [11, 15],
[Op.all]: sequelize.literal('SELECT 1'),
[Op.in]: [1, 2],
[Op.notIn]: [1, 2],
[Op.like]: '%hat',
[Op.notLike]: '%hat',
[Op.startsWith]: 'hat',
[Op.endsWith]: 'hat',
[Op.substring]: 'hat',
[Op.iLike]: '%hat',
[Op.notILike]: '%hat',
[Op.regexp]: '^[h|a|t]',
[Op.notRegexp]: '^[h|a|t]',
[Op.iRegexp]: '^[h|a|t]',
[Op.notIRegexp]: '^[h|a|t]',
[Op.any]: [2, 3],
[Op.like]: { [Op.any]: ['cat', 'hat'] }
}
}
});
Example 2: sequelize and
{ where: { [Op.and]: [{ Col1: val1 }, { Col2: val2 }]} }
Example 3: sequelize
$ npm install --save sequelize # This will install v5
$ npm install --save-dev sequelize-cli
# And one of the following:
$ npm install --save pg pg-hstore # Postgres
$ npm install --save mysql2
$ npm install --save mariadb
$ npm install --save sqlite3
$ npm install --save tedious # Microsoft SQL Server
$ npm install mysql2 -g
$ npm install -g sequelize-auto-v2
sequelize-auto -o "./models" -d schema -h localhost -u user -p 3306 -x password -e dialect
Exemple:
sequelize-auto -o "./models" -d nomeDoShema -h localhost -u usuarioDaConexao -p 3306 -x senhaDaConexao -e mysql
Example 4: sequelize documentation
const { Sequelize, Model, DataTypes } = require('sequelize');
const sequelize = new Sequelize('sqlite::memory:');
class User extends Model {}
User.init({
username: DataTypes.STRING,
birthday: DataTypes.DATE
}, { sequelize, modelName: 'user' });
sequelize.sync()
.then(() => User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20)
}))
.then(jane => {
console.log(jane.toJSON());
});