# Nodejs SQL ORM Sequelize 입문 4. 읽기(Read)

# Read Data by id

router.get('/:id', (req, res)=>{
  models.Post.findById(req.params.id)
    .then(result => {
      res.json(result)
    })
    .catch(err => {
      res.json(err)
    })
})
1
2
3
4
5
6
7
8
9

# Read Data All

just all data

router.get('/', function (req, res, next) {
  models.Post.findAll()
    .then(result => {
       res.json(result)
    })
    .catch(err => {
      res.json(err)
    })
})
1
2
3
4
5
6
7
8
9

# Read Datas by condition

where query

/* GET posts listing. */
router.get('/', function (req, res, next) {
  models.Post.findAll({
  where: {
      author_id: 3
  }
  })
    .then(result => {
       res.json(result)
    })
    .catch(err => {
      res.json(err)
    })
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14