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
730
SequelizeのPaginationで苦労した話
KSK
June 26, 2018
Tweet
Share
More Decks by KSK
See All by KSK
Supernova Studio 使いはじめてみたら割と良さそう / supernova_studio
ksk1030m
1
830
CSV出力 - Viewからやるか? 他からやるか? / How to output CSV
ksk1030m
1
610
4画面出力とレシート印刷で作る体験型デジタルサイネージ / Unity signage
ksk1030m
1
3.1k
実録リファラル採用-僕と副社長の1827日- / my referral
ksk1030m
0
1.2k
GitLabを仕事で使っていた私が思うことをつらつらと / about GitLab
ksk1030m
1
990
エンジニア目線で考えるPR戦略 / PR by Engineer
ksk1030m
1
1.4k
Metabase ライブ環境構築 / metabase_live_coding
ksk1030m
0
340
昔の自分に伝えたい容量回復のためのDockerの仕組み / docker_tips
ksk1030m
1
540
Capistranoの罠と他人がハマった事例を見て思うこと / capistrano-trap
ksk1030m
0
310
Other Decks in Programming
See All in Programming
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
990
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
9
2.6k
レガシープロジェクトで最大限AIの恩恵を受けられるようClaude Codeを利用する
tk1351
3
1.3k
コンテキストエンジニアリング Cursor編
kinopeee
1
710
AI OCR API on Lambdaを Datadogで可視化してみた
nealle
0
180
Laravel Boost 超入門
fire_arlo
1
130
一人でAIプロダクトを作るための工夫 〜技術選定・開発プロセス編〜 / I want AI to work harder
rkaga
13
2.8k
ゲームの物理
fadis
5
1.5k
エンジニアのための”最低限いい感じ”デザイン入門
shunshobon
0
130
WebAssemblyインタプリタを書く ~Component Modelを添えて~
ruccho
1
920
KessokuでDIでもgoroutineを活用する / Go Connect #6
mazrean
0
120
為你自己學 Python - 冷知識篇
eddie
1
200
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
329
21k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
We Have a Design System, Now What?
morganepeng
53
7.7k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Code Reviewing Like a Champion
maltzj
525
40k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
For a Future-Friendly Web
brad_frost
179
9.9k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
480
Facilitating Awesome Meetings
lara
55
6.5k
Designing Experiences People Love
moore
142
24k
Why Our Code Smells
bkeepers
PRO
338
57k
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ʂ