Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SequelizeのPaginationで苦労した話
Search
KSK
June 26, 2018
Programming
2
690
SequelizeのPaginationで苦労した話
KSK
June 26, 2018
Tweet
Share
More Decks by KSK
See All by KSK
Supernova Studio 使いはじめてみたら割と良さそう / supernova_studio
ksk1030m
1
740
CSV出力 - Viewからやるか? 他からやるか? / How to output CSV
ksk1030m
1
540
4画面出力とレシート印刷で作る体験型デジタルサイネージ / Unity signage
ksk1030m
1
2.9k
実録リファラル採用-僕と副社長の1827日- / my referral
ksk1030m
0
1.1k
GitLabを仕事で使っていた私が思うことをつらつらと / about GitLab
ksk1030m
1
900
エンジニア目線で考えるPR戦略 / PR by Engineer
ksk1030m
1
1.3k
Metabase ライブ環境構築 / metabase_live_coding
ksk1030m
0
290
昔の自分に伝えたい容量回復のためのDockerの仕組み / docker_tips
ksk1030m
1
470
Capistranoの罠と他人がハマった事例を見て思うこと / capistrano-trap
ksk1030m
0
270
Other Decks in Programming
See All in Programming
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
1
110
CSC509 Lecture 13
javiergs
PRO
0
110
Jakarta EE meets AI
ivargrimstad
0
640
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
3
250
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
250
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
360
Quine, Polyglot, 良いコード
qnighy
4
650
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
How GitHub (no longer) Works
holman
310
140k
Teambox: Starting and Learning
jrom
133
8.8k
Site-Speed That Sticks
csswizardry
0
33
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Rails Girls Zürich Keynote
gr2m
94
13k
Statistics for Hackers
jakevdp
796
220k
Building an army of robots
kneath
302
43k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
The Invisible Side of Design
smashingmag
298
50k
GitHub's CSS Performance
jonrohan
1030
460k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Done Done
chrislema
181
16k
Transcript
Sequelizeͷ PaginationͰ ۤ࿑ͨ͠ kskn / 2018.06.28 @Roppongi.js #4
ࣗݾհ ɾKeisuke Nakatane (@kskn) ɾORSO Inc. ৽نࣄۀ։ൃࣨ ɾαʔόɿΞϓϦɿϑϩϯτ ʹɹ̓ɹɿɹ̍ɹɿɹ̎ɹɹ͘Β͍ ɾલ৬ژͷήʔϜͰਓࣄ
ߏͬ͘͟Γ͜Μͳײ͡ ʢཧπʔϧʣ ʢΞϓϦʣ ʢAPIαʔόʣ
What’s Sequelizeʁ
None
Sequelize ɾNode.js ༻ͷOR Mapper ɹ- http://docs.sequelizejs.com/ ɹ- Rails Ͱ͍͏Active Record
ɾҰ൪ϝδϟʔͰΓ͍ͨ͜ͱͰ͖ͦ͏ ɾݹ͍ใώοτ͢ΔͷͰҙ (ver 3.x) ɹ- ࠷৽ ver 4.38 ͱ ver 5 Beta (2018/06/24)
How to Paginate
Pagination ɾOffset ɹ- ࠷ॳ͔Β nϨίʔυΛಡΈඈ͢ ɹɹˠ ख͚ܰͩͲύϑΥʔϚϯεͱਫ਼ ❌ ɾCursor ɹ-
SELECT ͷ։࢝ҐஔΛࢦఆ ɹɹˠ ͬͪ͜ͰΓ͍ͨ
Pagination ɾOffset ɹ- ࠷ॳ͔Β nϨίʔυΛಡΈඈ͢ ɹɹˠ ख͚ܰͩͲύϑΥʔϚϯεͱਫ਼ ɾCursor ʢࣺͯΔʣ ʢಡ·ͳ͍ʣ
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
Pagination / multi cursor ɾෳΧϥϜͰιʔτ͢Δ߹Ͳ͏ͳΔ͔ʁ ɹˠ ߦࣜ SELECT * FROM
users ɹWHERE (age, id) > (20, 30) ɹORDER BY age, id ɹLIMIT 10
by Sequelizeʁ
by Sequelize ɾ୯ҰΧϥϜͷ߹ ɹ- $gt ʮ > ʯ(greater than)
User.findAll({ ɹwhere: { id: { $gt: 30 } }, ɹorder: [['id', 'ASC']], ɹlimit: 10, })
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, })
Summary ɾ࣮ࡍ൚༻ϞδϡʔϧԽΛࢦͨ݁͠Ռɺ ɹຐվؾຯ… ɹ- GraphQLͱͷབྷΈ ɹ- GROUP BYͱซ༻Ͱ͖ΔΑ͏ʹ ɹ- DATEܕͷ߹CASTͨ͠Γ
ɾGarphQLରԠࠐΈͰϥΠϒϥϦԽͰ͖ͨΒ ɹधཁ͋Δʁ ɾSequelizeɺѱ͘ͳ͍ͱࢥ͏Αʂ
Thank you for listeningʂ