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
770
Other Decks in Programming
See All in Programming
SwiftUI Viewの責務分離
elmetal
PRO
2
260
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
910
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
290
CloudNativePGを布教したい
nnaka2992
0
110
React 19アップデートのために必要なこと
uhyo
7
1.4k
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
150
バッチを作らなきゃとなったときに考えること
irof
2
500
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
150
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
250
Honoとフロントエンドの 型安全性について
yodaka
7
1.4k
Django NinjaによるAPI開発の効率化とリプレースの実践
kashewnuts
1
240
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
170
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
114
50k
For a Future-Friendly Web
brad_frost
176
9.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Being A Developer After 40
akosma
89
590k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
A better future with KSS
kneath
238
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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 ͷҠߦߟྀ͢Δ͕ͱͯଟ͍ ʢಛʹඅ༻໘ʣͷͰɺ Ҡߦ͢ΔࡍྉۚͱͷݟੵΓΛೖ೦ʹߦ͍·͠ΐ͏ ʢռΊʣ