Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ためしてmBaaS

Avatar for yospig yospig
December 24, 2019

 ためしてmBaaS

社内勉強会の公開用。
Firebaseの入門記録。

Avatar for yospig

yospig

December 24, 2019

Other Decks in Programming

Transcript

  1. mBaaS is 何 3 • mBaaS(mobile backend as a Service)


    • モバイル向けのバックエンドの面倒な部分をイロイロ提供
 ◦ ユーザ認証(google, Twitter, Facebook, LINE, Mail, etc…)
 ◦ プッシュ通知
 ◦ 監視
 ◦ Webサイトホスティング
 ◦ リアルタイムデータベース

  2. 5 • Microsoft Azure
 ◦ Azureのサービスのひとつ
 • AWS Mobile
 ◦

    さらにAWS AppSync, AWS Amplifyなんてのもある 
 • Cloud Endpoints
 ◦ FirebaseがあるのにGCPにもある 
 ◦ GAEも似たような機能がある 
 mBaaSいっぱいある
  3. 9 • 開発環境
 ◦ Firebase CLI, SDKをインストール
 ▪ % npm

    install -g firebase-tools
 ▪ npm install firebase-functions@latest firebase-admin@latest --save
 ◦ ログイン
 ▪ % firebase login
 ▪ % firebase list
 リファレンス:https://firebase.google.com/docs/cli/?hl=ja
  4. 11 • Cloud Firestore
 ◦ NoSQL
 ◦ Realtime Databaseよりも多彩で高速なクエリ
 ◦

    設定
 ▪ DatabaseはGCPのリージョンを指定する
 ▪ 一度決めると変更ができない
 ▪ 基本は `asia-northeast1(東京)`
 ▪ 注) Realtime Databaseは常に `us-central1` 

  5. Cloud Firestore is 何 12 • ドキュメント指向データベース
 ◦ 「テーブル」「行」はない
 ◦

    「ドキュメント」に格納され「コレクション」にまとめる
 • データの型は用意されている
 ◦ e.g. ブール値, 数値, 文字列, 地理的位置, blob, timestamp
 ◦ 型の追加ができる(サイズは1MB制限)
 ◦ 型はあるが制約ではない

  6. 15 • コレクション
 ◦ ドキュメントだけを格納するコンテナ
 ◦ コレクション内のドキュメント名は一意
 ◦ ユーザID的な独自キーを指定 or

    ランダムID
 ◦ コレクションは作成/削除はしない
 ◦ ドキュメントが作られればコレクションは勝手に作られる
 ◦ ドキュメントがなくなればコレクションも無くなる
 Cloud Firestore
  7. 17 `users` コレクションに
 `ishimaru` を表わすドキュメントを格納する
 
 + Users
 + Ishimaru


    + birth:1983/07/12
 + Name
 + First:Yosuke
 + Last:Ishimaru
 ← コレクション
 ← ドキュメント
 ← フィールド
 ← フィールド(マップ)

  8. 18 date
 - 20191224
 - year: 2019
 - month: 12


    - day: 24
 - user
 - ishimaru
 - clock_in: ‘09:00’
 - clock_out: ‘17:30’
 REST イメージ パターンA 日付から引く /date/20191224/user/ishimaru/ 出退勤のデータ構造を表すなら?
  9. 19 date
 - 20191224
 - year: 2019
 - month: 12


    - day: 24
 - user
 - ishimaru
 - clock_in: ‘09:00’
 - clock_out: ‘17:30’
 RESTイメージ パターンA 日付から引く /date/20191224/user/ishimaru/ 出退勤のデータ構造を表すなら? 特定ユーザで期間を指定したい場合
 
 - 日付のdocを絞り込む
 - 疑似likeか?orができないので制約が不安)
 - 対象のdateDocから更にユーザを絞り込むために ループする?
 → 面倒くさい

  10. 20 User
 - ishimaru
 - date
 - 20191224
 - year:

    2019
 - month: 12
 - day: 24
 - clock in: ‘09:00’
 - clock out: ‘17:30’
 RESTイメージ パターンB 人から引く /user/ishimaru/date/20191224/ 出退勤のデータ構造を表すなら?
  11. 21 User
 - ishimaru
 - year
 - 2019
 - year:

    2019
 - month
 - 12
 - month: 12
 - day: 24
 - clock in: ‘09:00’
 RESTイメージ パターンC サブコレクションネスト /user/ishimaru/year/2019/month/12/ 出退勤のデータ構造を表すなら?