select all sequelize code example

Example 1: sequelize limit

const Op = Sequelize.Op;

app.get('/notes/search', function(req, res) {
  Note.findAll({
    limit: 2,
    where: {
      tag: {
        [Op.or]: [].concat(req.query.tag)
      }
    }
  }).then(notes => res.json(notes));
});

Example 2: op in sequelize

//First method
// selecting authorityId :12 or 13
model.findAll({
  where: {
    [Op.or]: [
      { authorId: 12 },
      { authorId: 13 }
    ]
  }
});

Example 3: sequelize like search

const Sequelize = require('sequelize');
const Op = Sequelize.Op;

let data: Array<any> = await MyDataSequelizeAccess.findAll({
  where: {
    name: {
      [Op.like]: '%Bob%'
    }
  }
});

Example 4: sequelize .all()

yourTableModel.findAll({
  //optional filters
  where: {},
  raw: true,
})

Example 5: sequelize not equal

const { Op } = require("sequelize");
column: {[Op.ne]: value},

Tags:

Misc Example