Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SequelizeのPaginationで苦労した話

KSK
June 26, 2018

 SequelizeのPaginationで苦労した話

KSK

June 26, 2018
Tweet

More Decks by KSK

Other Decks in Programming

Transcript

  1. Sequelize ɾNode.js ༻ͷOR Mapper ɹ- http://docs.sequelizejs.com/ ɹ- Rails Ͱ͍͏Active Record

    ɾҰ൪ϝδϟʔͰ΍Γ͍ͨ͜ͱ͸Ͱ͖ͦ͏ ɾݹ͍৘ใ΋ώοτ͢ΔͷͰ஫ҙ (ver 3.x) ɹ- ࠷৽͸ ver 4.38 ͱ ver 5 Beta (2018/06/24)
  2. Pagination ɾOffset ɹ- ࠷ॳ͔Β nϨίʔυΛಡΈඈ͹͢ ɹɹˠ ख͚ܰͩͲύϑΥʔϚϯεͱਫ਼౓ ɾCursor SELECT *

    FROM users ɹORDER BY id LIMIT 10 OFFSET 30 SELECT * FROM users ɹWHERE id > 30 ORDER BY id LIMIT 10
  3. Pagination / multi cursor ɾෳ਺ΧϥϜͰιʔτ͢Δ৔߹Ͳ͏ͳΔ͔ʁ ɹˠ ߦ஋ࣜ SELECT * FROM

    users ɹWHERE (age, id) > (20, 30) ɹORDER BY age, id ɹLIMIT 10
  4. by Sequelize ɾ୯ҰΧϥϜͷ৔߹ ɹ- $gt ͸ ʮ > ʯ(greater than)

    User.findAll({ ɹwhere: { id: { $gt: 30 } }, ɹorder: [['id', 'ASC']], ɹlimit: 10, })
  5. by Sequelize / multi cursor ɾΧϥϜʹ (age, id) Έ͍ͨͳࢦఆ͸Ͱ͖ͳ͍ ɾsequelize.literal('

    SQLจ ‘) Ͱ௚઀ॻ͚Δ User.findAll({ ɹwhere: ɹɹsequelize.literal('(age, id) > (20, 30)'), ɹorder: [['age', 'ASC'], ['id', 'ASC']], ɹlimit: 10, })