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
API を Firebase Realtime Database に移行して気付いたこと ver2
Search
syamaoka
October 20, 2017
Programming
1
500
API を Firebase Realtime Database に移行して気付いたこと ver2
iOSDC 2017 Reject Conference days2
syamaoka
October 20, 2017
Tweet
Share
More Decks by syamaoka
See All by syamaoka
API を Firebase Realtime Database に移行して気付いたこと
bpyamasinn
1
790
Other Decks in Programming
See All in Programming
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
460
Processing Gem ベースの、2D レトロゲームエンジンの開発
tokujiros
2
130
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
330
rage against annotate_predecessor
junk0612
0
170
CloudflareのChat Agent Starter Kitで簡単!AIチャットボット構築
syumai
2
510
知っているようで知らない"rails new"の世界 / The World of "rails new" You Think You Know but Don't
luccafort
PRO
1
180
print("Hello, World")
eddie
2
530
Improving my own Ruby thereafter
sisshiki1969
1
160
楽して成果を出すためのセルフリソース管理
clipnote
0
180
機能追加とリーダー業務の類似性
rinchoku
2
1.3k
旅行プランAIエージェント開発の裏側
ippo012
2
920
Kiroで始めるAI-DLC
kaonash
2
610
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
140
7.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Producing Creativity
orderedlist
PRO
347
40k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
Fireside Chat
paigeccino
39
3.6k
Code Review Best Practice
trishagee
71
19k
Making the Leap to Tech Lead
cromwellryan
135
9.5k
GitHub's CSS Performance
jonrohan
1032
460k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
Making Projects Easy
brettharned
117
6.4k
The Cult of Friendly URLs
andyhume
79
6.6k
Navigating Team Friction
lara
189
15k
Transcript
API Λ Firebase Realtime Database ʹ Ҡߦͯ͠ؾ͍ͨ͜ͱ 2017/10/20 syamaoka iOSDC
2017 Reject Conference days2
ࣗݾհ ໊લɿ ࢁԬ ਅ ( syamaoka ) झຯɿ ɾ MoBA
: VainGlory ୲ɿ ɾ iOS, όοΫΤϯυ
ҙ ⚠ ͜ͷൃද Firebase Realtime Database 8ׂ, iOS 2ׂͷߏͰ ͢
iOS͕ςʔϚͰ͕͢ɺ ࠓճ Realtime Database (ҎԼRTDB) ʹ͍ͭͯͲΜͲΜޠͬ ͍͖ͯ·͢ʂ
࠷ॳʹɾɾ
ϦδΣΫτ͞Εͯ Α͔ͬͨ !
Կނʁ ʮRTDB ༷ʑͳΞϓϦͰ͑Δʯ Λओு͔ͨͬͨ͠ ! ͔͠͠ɺ৽͍͠ RTDB ͷ࣍ੈσʔλϕʔε ͕ൃද͞Ε·͠ ͨɻ
Cloud Firestore ެ։
୲தͷαʔϏεͰ༻͍ͯ͠Δػೳ • Realtime Database • Remote Config • Firebase Authentication
• Analytics • App Indexing • Firebase Performance Monitoring
୲தαʔϏεͰꙍ ֵአͭͼ͚Ρ䱛ᚆ • Realtime Database <- ͜͜த৺!ʢFirestore ͍͍ͨ"ʣ • Remote
Config • Firebase Authentication • Analytics • App Indexing • Firebase Performance Monitoring
ΞδΣϯμ • API -> RTDB • Client Side Join •
RTDB ͷ௨৴ྔ֬ೝํ๏ • API, RTDB, Firestore ͷൺֱ
API -> RTDB
RTDB ʹٻΊ͍ͯΔ͜ͱ • API ࡞ͷܰݮ • ύϑΥʔϚϯενϡʔχϯά͔Βͷ٫ • ΦϑϥΠϯ࣌ͷσʔλͷѻ͍͢͞ʢॲཧͷ؆୯͞ʣ
ҠߦͰҰ൪ࠔͬͨͷɺ߹ੑ ! Firebase RDB Ͱͳ͍ͨΊɺ֎෦Ωʔ੍͕͋Γ·ͤΜɻ ͦͷͨΊɺ݁߹͕ඞཁͳՕॴొ͢ΔࡍʹίʔυͰ֬ೝɻ εΩʔϚϨεͰɺ݁߹͖͔͢൱͔Λஅ͠ɺ ࠷దͳઃܭΛ͍ͯ͘͠ͷ͕ॏཁͰ͢ɻ !
ΤϯδχΞͷͷݟͤॴ !
͕ͣͩͬͨɾɾʂ
Firestore Ͱɺ ͋Δఔղফ͞ΕΔ !
Firestore ͷ৽͍͠σʔλܕ "Reference" Λ͏
RTDB ͷ߹ let articleId: String // primary key let categoryId:
String // foreign key let title: String // ͦͷଞͷϑΟʔϧυ { "articles" : { "articleId1" : { "title" : "λΠτϧ", "category" : "categoryId1" } }, "categories" : { "categoryId1" : { "name": "ήʔϜ" } } }
RTDB ͷ߹ let articleId: String // primary key let categoryId:
String // foreign key let title: String // ͦͷଞͷϑΟʔϧυ { "articles" : { "articleId1" : { "title" : "λΠτϧ", "category" : "categoryId1" <- ͜Ε͕ category Ͱ͋Δͱ͍͏อূग़དྷͳ͍ ! } }, "categories" : { "categoryId1" : { "name": "ήʔϜ" } } }
Firestore ͷ߹ let articleId: String // primary key let categoryId:
DocumentReference // foreign key let title: String // ͦͷଞͷϑΟʔϧυ
ιʔτ
RTDB ͷιʔτͷಛ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍
RTDB ͷιʔτͷಛ • ΩʔΛࢦఆͯ͠ঢॱͰऔಘ • ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍
ฦ٫͢Δσʔλͷॱ൪อূ͍ͯ͠ͳ͍ (ྫ) ࠷৽σʔλΛ 3 ݅औಘ͢ΔͨΊɺ࡞࣌Ͱιʔτ͢Δ reference.child("articles").queryLimited(toFirst: 3).orderBy("created")
None
݁Ռ ฦ٫͞ΕΔσʔλ࠷৽σʔλͷ 3 ͕݅ͩɺ ฦ٫͞ΕΔ JSON ͷฒͼॱอূ͞Ε͍ͯͳ͍ Ҿ༻ݩ: https://firebase.google.com/docs/database/rest/retrieve-data?hl=ja#section-rest- ordered-data
Q. ΞϓϦଆͲ͏͢Ε͍͍ʁ A. ฦ٫͞ΕͨΛιʔτ͢͠ɻ
͕ͣͩͬͨɾɾʂ
Firestore Ͱ ղফ͞ΕΔ !
Firestore (ιʔτฤ) • ߱ॱʹରԠ ৄࡉͪ͜Β • ෳ߹ Index ʹରԠ ৄࡉͪ͜Β
• ฦ٫͞ΕΔσʔλͷฒͼॱ͕ἧ͍ͬͯΔ
RTDB Ͱ߱ॱʹ͢Δʹʁ ͪ͜ΒΛࢀর͍ͯͩ͘͠͞ ! https://speakerdeck.com/bpyamasinn/api-wo-firebase- realtime-database-niyi-xing-siteqi-fu-itakoto
ϩδοΫॱʹ͢Δʹʁ ϩδοΫʹΑΔฒͼॱɺ DB Λࢀর͢Δํ๏Ͱ͍͠
Index ࡞ { "articleOrders": { "articleId1": 1, "articleId2": 2 }
}
ϝϦοτ • ࠷খݶͷࢀর • ΞϓϦଆͷมߋͳ͠Ͱॱ൪Λมߋग़དྷΔ ※ articles ͷதʹ order Λ༻ҙͨ͠߹ɺarticles
શͯΛಡ ΈࠐΉඞཁ͕͋ΓɺύϑΥʔϚϯε͕ѱ͍ ❌
σϝϦοτ • ߋ৽ִ͕ؒ͘ग़དྷͳ͍ • ̍࣌ؒຖͷߋ৽Ͱ͋Εେৎ͕ͩɺ5ຖͳͲ͘͢Ε ͢Δ΄Ͳίετ͕େ͖͘ͳΔ • ϩδοΫʹݶք͕͋Δ • ཪͰॲཧͯ͠Δͷ௨৴ྔ͕૿͑Δ
σϝϦοτ • ߋ৽ִ͕ؒ͘ग़དྷͳ͍ • ̍࣌ؒຖͷߋ৽Ͱ͋Εେৎ͕ͩɺ5ຖͳͲ͘͢Ε ͢Δ΄Ͳίετ͕େ͖͘ͳΔ • ϩδοΫʹݶք͕͋Δ • ཪͰॲཧͯ͠Δͷ௨৴ྔ͕૿͑Δ
্هͷσϝϦοτ͕ڐ༰ग़དྷͳ͍αʔϏεͷ߹ɺAPI Ͱ։ ൃͨ͠ํ͕Α͍͔
Client Side Join Client Side Join RTDB ͱ Firestore
྆ํͰ͑Δख๏
σʔλྫ
RTDB { "articles" : { "hogeId" : { "title" :
"λΠτϧ", "category" : "categoryID_1" } }, "categories" : { "categoryID_1" : { "name": "ήʔϜ" } } }
Firestore
RTDB ͷ Client Side Join Λલఏͱ͠ ͨΞʔΩςΫνϟʹ͢Δඞཁ͕͋Δ
None
None
None
None
݁߹ͷྲྀΕ 1. articles ͱ categories ͷ Observable Λ༻ҙ 2. RxSwift
ΦϖϨʔλ zip Λར༻ Observable.zip(articles, categories)ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹ 1. ྆σʔλΛ݁߹͠ɺมॲཧΛ͔͚Δ Observable.zip(articles, categories) {($0, $1)}.map(Translator())
RTDB ͷ௨৴ྔ֬ೝํ๏
ํ๏ 3ͭ • Xcode Ͱ௨৴ྔΛݟΔ • Charles Ͱ௨৴ྔΛݟΔ • Firebase
CLI ͷ profile Ͱ௨৴ྔΛݟΔ
ํ๏ 3ͭ • Xcode Ͱ௨৴ྔΛݟΔ • Charles Ͱ௨৴ྔΛݟΔ • Firebase
CLI ͷ profile Ͱ௨৴ྔΛݟΔ <- ͜͜ͷ͓Λ͠· ͢
Firebase CLI ͱʁ Firebase ϓϩδΣΫτͷཧɺදࣔɺσϓϩΠΛߦ͏ͨΊͷ ͞·͟·ͳπʔϧΛఏڙͯ͘͠ΕΔ Command Line Interface
͍ํ 1. https://firebase.google.com/docs/cli/?hl=ja ͷಋೖखॱʹै ͏ 2. iPhone γϛϡϨʔλΛ্ཱͪ͛Δ 3. firebase
database:profile --project {ϓϩδΣΫτID} Λ λʔϛφϧͰ࣮ߦ 4. iPhone γϛϡϨʔλͰܭଌ͍ͨ͠खॱͰಈ͔͢
݁Ռը໘
ҙ ⚠ ͜ͷ௨৴ྔ࣮ࡍͷμϯϩʔυྔΑΓগͳ͍ͷͰɺ͋͘·Ͱ ࢀߟͰ͢ Ҿ༻ : https://firebase.google.com/docs/database/usage/profile
API, RTDB, Firestore ൺֱ
API ͕༏Ε͍ͯΔ • ΞϓϦଆͷ࣮͕γϯϓϧ • WebαʔϏεల։͍ͯ͠Δ߹ɺAPI Λ͍·ΘͤΔ • Ωϟογϡώοτ͕ߴ͍αʔϏεྉ͕ۚ҆͘͢Ή •
ϦϦʔεޙʹ͕ൃੜͨ࣌͠ʹɺAPI ଆͰΧόʔ͍͢͠
API ͕༏Ε͍ͯΔ • ΞϓϦଆͷ࣮͕γϯϓϧ • WebαʔϏεల։͍ͯ͠Δ߹ɺAPI Λ͍·ΘͤΔ • Ωϟογϡώοτ͕ߴ͍αʔϏεྉ͕ۚ҆͘͢Ή •
ϦϦʔεޙʹ͕ൃੜͨ࣌͠ʹɺAPI ଆͰΧόʔ͍͢͠ ....(ਖ਼ɺࢁ΄Ͳ͋Δ ! )
RTDB ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • ΦϑϥΠϯରԠָ͕ • ӡ༻͞Ε͍ͯΔͷͰɺࢀߟʹͳΔهࣄ͕ଟ͍
Firestore ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • RTDB ͱൺͯ ΦϑϥΠϯରԠָ͕ •
RTDB ͱൺͯ order, query ͕༏Ε͍ͯΔ • ࠓޙͲΜͲΜ৽͍͠ػೳ͕Ճ͞Ε͍ͯ͘༧ఆ • ՝ۚϞσϧ͕௨৴ྔͰͳ͘ɺࢀরճͳͷͰઅ͍͢͠
Firestore ͕༏Ε͍ͯΔ • API ͷ։ൃ͕ෆཁ • RTDB ͱൺͯ ΦϑϥΠϯରԠָ͕ •
RTDB ͱൺͯ order, query ͕༏Ε͍ͯΔ • ࠓޙͲΜͲΜ৽͍͠ػೳ͕Ճ͞Ε͍ͯ͘༧ఆ • ՝ۚϞσϧ͕௨৴ྔͰͳ͘ɺࢀরճͳͷͰઅ͍͢͠ ....( RTDB ͱൺֱ͍͍ͯ͠ॴଞʹ͋Δ ! )
Firestore ͷαϯϓϧͪ͜Β https://github.com/firebase/quickstart-ios/tree/master/ firestore
Bolt Firestore ʹରԠ͢Δ https://github.com/firebase/bolt/issues/216
·ͱΊ • RTDB ૉΒ͍͠ɻͨͩɺFirestore ͬͱૉΒ͍͠ ! • σʔλͷ݁߹ΛΞϓϦଆͰߦ͏࣌ RxSwift ͷ
zip Λ͏ͱ ؆୯ʹ࣮͕Մೳ • API -> RTDB, Firestore ͷҠߦߟྀ͢Δ͕ͱͯଟ͍ ʢಛʹඅ༻໘ʣͷͰɺ Ҡߦ͢ΔࡍྉۚͱͷݟੵΓΛೖ೦ʹߦ͍·͠ΐ͏ ʢռΊʣ