Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about datastore #2

Open
LeoAndo opened this issue Feb 16, 2022 · 5 comments
Open

about datastore #2

LeoAndo opened this issue Feb 16, 2022 · 5 comments

Comments

@LeoAndo
Copy link
Owner

LeoAndo commented Feb 16, 2022

DataStore とは

DataStore は、SharedPreferences に代わるものとして改善された新しいデータ ストレージ ソリューションです。Kotlin のコルーチンと Flow に基づいて構築された DataStore には、次の 2 種類の実装があります。プロトコル バッファに基づく型付きオブジェクトを保存する Proto DataStore と、Key-Value ペアを保存する Preferences DataStore です。データは非同期で一貫性を持ちトランザクションとして保存されるため、SharedPreferences の欠点の一部が解消されます。

スクリーンショット 2022-02-16 17 58 44

#refs
https://developer.android.com/codelabs/android-preferences-datastore#3

@LeoAndo
Copy link
Owner Author

LeoAndo commented Feb 16, 2022

preferences DatatStore vs Proto DataStore

https://youtu.be/mdQjuZbLv9Y?list=PLWz5rJ2EKKc8to3Ere-ePuco69yBUmQ9C&t=288

preferences DataStore

  • Key Valueのペアで管理
  • 型安全ではない

Proto DataStore

  • 型安全
  • プロトコル バッファを使用してスキーマを定義します。Protobufs を使用すると、強力に型付けされたデータを引き継ぎできます

@LeoAndo
Copy link
Owner Author

LeoAndo commented Feb 16, 2022

Preferences DataStore の概要

  • データ更新をトランザクションとして処理する
  • データの現在の状態を表す Flow を公開する
  • データの永続化メソッドがない(apply()、commit())
  • 内部状態への変更可能な参照が返されない
  • 型付けされたキーを使用して Map や MutableMap のような API を公開する

メモ

@LeoAndo
Copy link
Owner Author

LeoAndo commented Feb 16, 2022

Proto DataStore - 概要

SharedPreferences と Preferences DataStore の欠点のひとつとして、スキーマを定義したりキーへのアクセスが正しい型によるものか確認したりする方法がないということが挙げられます。Proto DataStore では、プロトコル バッファを使用してスキーマを定義することで、この問題に対処します。Proto DataStore を使用すると、格納される型が認識され、その型のみが提供されるので、キーを使用する必要がなくなります。

メモ

スクリーンショット 2022-02-16 21 50 51

@LeoAndo
Copy link
Owner Author

LeoAndo commented Feb 16, 2022

protocol-buffersの編集にはプラグインを入れる必要がある

https://plugins.jetbrains.com/plugin/14004-protocol-buffers

スクリーンショット 2022-02-16 21 39 59

@LeoAndo LeoAndo changed the title datastoreについて about datastore Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant