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
700
SequelizeのPaginationで苦労した話
KSK
June 26, 2018
Tweet
Share
More Decks by KSK
See All by KSK
Supernova Studio 使いはじめてみたら割と良さそう / supernova_studio
ksk1030m
1
760
CSV出力 - Viewからやるか? 他からやるか? / How to output CSV
ksk1030m
1
560
4画面出力とレシート印刷で作る体験型デジタルサイネージ / Unity signage
ksk1030m
1
2.9k
実録リファラル採用-僕と副社長の1827日- / my referral
ksk1030m
0
1.1k
GitLabを仕事で使っていた私が思うことをつらつらと / about GitLab
ksk1030m
1
920
エンジニア目線で考えるPR戦略 / PR by Engineer
ksk1030m
1
1.3k
Metabase ライブ環境構築 / metabase_live_coding
ksk1030m
0
300
昔の自分に伝えたい容量回復のためのDockerの仕組み / docker_tips
ksk1030m
1
490
Capistranoの罠と他人がハマった事例を見て思うこと / capistrano-trap
ksk1030m
0
280
Other Decks in Programming
See All in Programming
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
240
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
550
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
740
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
360
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
400
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
1.2k
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
5.8k
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
230
快速入門可觀測性
blueswen
0
480
Zoneless Testing
rainerhahnekamp
0
150
MCP with Cloudflare Workers
yusukebe
2
270
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.8k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
550
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
19
2.3k
Practical Orchestrator
shlominoach
186
10k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Facilitating Awesome Meetings
lara
50
6.2k
Unsuck your backbone
ammeep
669
57k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
The Cult of Friendly URLs
andyhume
78
6.1k
Become a Pro
speakerdeck
PRO
26
5.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
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ʂ