Querying Using Models


Official Docs

Finds a single instance that matches the search criteria (even if there are more than one that match the search criteria - it will return the first it finds)

const foundPug = await Pug.findOne({
  where: {name: 'Cody'}



Official Docs

Finds the instance with the specified id.

pugWithIdOne = await Pug.findById(1)



Official Docs

Finds all instances that match the search criteria. If no criteria are given, it returns all the instances in the table.

const allPugs = await Pug.findAll() // will find ALL the pugs!


"Select" Clauses ("attributes")

Official Docs

You can select specific columns to be included in the returned instance by specifying an "attributes" array.

const allPugs = await Pug.findAll({
  attributes: ['id', 'name', 'age'] // like saying: SELECT id, name, age from pugs;

console.log(allPugs) // [{id: 1, name: 'Cody', age: 7}, {id: 2, name: "Murphy", age: 4}]
// note that all the pugs only have key-value pairs for id, name and age included

"Where" Clauses

Official Docs

You can narrow down the search in a findAll by specifying a where clause

const sevenYearOldPugs = await Pug.findAll({
  where: { // like saying: SELECT * from pugs WHERE age = 7;
    age: 7,


Specifying multiple options uses "AND" logic

const sevenYearOldBlackPugs = await Pug.findAll({
  where: { // like saying: SELECT * from pugs WHERE age = 7 AND color = 'black';
    age: 7,
    color: 'black'


Note: To specify comparisons like "greater than" and "less than", Check out Search Operators.