SequelizeのPaginationで苦労した話

1741ebf45ce415e49fb0340da9e1ca15?s=47 KSK
June 26, 2018

 SequelizeのPaginationで苦労した話

1741ebf45ce415e49fb0340da9e1ca15?s=128

KSK

June 26, 2018
Tweet

Transcript

  1. 5.
  2. 6.

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

    ɾҰ൪ϝδϟʔͰ΍Γ͍ͨ͜ͱ͸Ͱ͖ͦ͏ ɾݹ͍৘ใ΋ώοτ͢ΔͷͰ஫ҙ (ver 3.x) ɹ- ࠷৽͸ ver 4.38 ͱ ver 5 Beta (2018/06/24)
  3. 10.

    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
  4. 11.

    Pagination / multi cursor ɾෳ਺ΧϥϜͰιʔτ͢Δ৔߹Ͳ͏ͳΔ͔ʁ ɹˠ ߦ஋ࣜ SELECT * FROM

    users ɹWHERE (age, id) > (20, 30) ɹORDER BY age, id ɹLIMIT 10
  5. 13.

    by Sequelize ɾ୯ҰΧϥϜͷ৔߹ ɹ- $gt ͸ ʮ > ʯ(greater than)

    User.findAll({ ɹwhere: { id: { $gt: 30 } }, ɹorder: [['id', 'ASC']], ɹlimit: 10, })
  6. 14.

    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, })