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
3 libraries you want to keep in mind for realm
Search
daimarom
December 19, 2017
Programming
0
460
3 libraries you want to keep in mind for realm
Realmを導入するなら覚えておきたいライブラリ三選
potatotips#46
https://potatotips.connpass.com/event/73328/
daimarom
December 19, 2017
Tweet
Share
More Decks by daimarom
See All by daimarom
(Flutterテストの)沼にハマってやってみた
daimarom
2
1.6k
角丸? それxfermodeで出来るよ
daimarom
0
370
Other Decks in Programming
See All in Programming
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
180
Oxlintはいいぞ
yug1224
5
1.4k
Package Management Learnings from Homebrew
mikemcquaid
0
230
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
280
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
990
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
140
AI時代の認知負荷との向き合い方
optfit
0
160
今から始めるClaude Code超入門
448jp
8
9k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.1k
A designer walks into a library…
pauljervisheath
210
24k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
BBQ
matthewcrist
89
10k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Everyday Curiosity
cassininazir
0
130
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
67
Designing for humans not robots
tammielis
254
26k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
390
Information Architects: The Missing Link in Design Systems
soysaucechin
0
780
Transcript
Realmを導入するなら 覚えておきたい ライブラリ三選 potatotips#46 2017.12.18
自己紹介 面白法人カヤック / ゲームコミュニティ事業部(Lobi、Lobiトーナメント) 室山大輔 Lobi(※) アプリエンジニア(Android) ※ スマホゲームに特化したSNS
Realm The perfect backend for the next generation of reactive
mobile apps 次世代のリアクティブなモバイルアプリのための完璧なバックエンド APIがシンプルなので、実装がとても楽 とにかく速い(特にquery) 中の人に直接質問できる公式のslackチャンネルがある しかし Realm Java にはちょっと面倒な手続きが…
Realmにおけるモデルクラスの制約 • 引数なしのコンストラクタが必要 • getter, setterが必要だった • 差分アップデートをしたければ、ビルダーを 用意するなりして、自分で何とかする 大抵は
Android Studio が自動生成してくれる 本質的ではないコードを用意するのは少し面倒 モデルクラスが増えれば、更に面倒に public class TestEntity extends RealmObject { @PrimaryKey public String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public TestEntity() { } public TestEntity(String id) { this.id = id; } }
lombok Project Lombok getter/setter, equals/hashCode, toString など ボイラープレートコードをコンパイル時に自動生成 コードがだいぶシンプルになる フィールド名の変更などにも、自動で追従
便利なアノテーションが他にもある(@Builder, @Value など) Javaのプロダクトであれば使える @NoArgsConstructor @AllArgsConstructor @Getter @Setter public class TestEntity extends RealmObject { @PrimaryKey public String id; }
フィールドの指定 Realmは、モデルクラスからスキーマを自動生成する 様々なタイミングでフィールド名(文字列)が必要 マジックストリングを毎度書くのは面倒だし、ミスしそうで怖い そもそも避けたい # クエリ RealmResults<TestEntity> results =
realm.where(TestEntity.class) .equalTo("name", "hoge") .equalTo("child.name", "fuga") .findAll(); # マイグレーション schema.create(TestEntity.class.getSimpleName()) .addField("name", String.class, FieldAttribute.INDEXED) .addField("description", String.class, FieldAttribute.INDEXED) .addRealmObjectField("child", childSchema);
Realm Field Names Helper cmelchior/realmfieldnameshelper フィールド名(文字列)の定数を自動生成 ちょっと面倒なリンククエリ用の定数も生成してくれる # マイグレーション schema.create(TestEntity.class.getSimpleName())
.addField(TestEntityFields.NAME, String.class, FieldAttribute.INDEXED) .addField(TestEntityFields.CHILD.NAME, String.class, FieldAttribute.INDEXED) .addRealmObjectField(TestEntityFields.CHILD.$, childSchema); # クエリ RealmResults<TestEntity> results = realm.where(TestEntity.class) .equalTo(TestEntityFields.NAME, "hoge") .equalTo(TestEntityFields.CHILD.NAME, "fuga") .findAll();
デバッグログ 動作ログ、パフォーマンス計測、ボトルネックの特定、引数・返り値の確認など さまざまな用途でデバッグログの出力が必要 毎回自分で書くのは面倒 ビルドタイプに応じて、ログ出力の有無を 制御しないと、パフォーマンスに影響 public RealmResult<TestEntity> getTest() {
TimingLogger logger = new TimingLogger(TAG, "getTest"); Realm realm = getRealm(); logger.addSplit("get realm"); RealmResults<TestEntity> results = realm.where(TestEntity.class) .equalTo(TestEntityFields.NAME, "hoge") .equalTo(TestEntityFields.CHILD.NAME, "fuga") .findAll(); logger.addSplit("get test"); logger.dumpToLog(); return result; }
Hugo JakeWharton/hugo メソッドの引数・返り値、実行時間を自動出力 デバッグビルドの場合のみ出力 @DebugLog public RealmResult<TestEntity> getTest() { Realm
realm = getRealm(); RealmResults<TestEntity> results = realm.where(TestEntity.class) .equalTo(TestEntityFields.NAME, "hoge") .equalTo(TestEntityFields.CHILD.NAME, "fuga") .findAll(); return result; } # logcat V/TestProviderImpl: ⇢ getTest() V/TestProviderImpl: ⇠ getTest [2ms] = []
まとめ Realmはすごくいい感じ 今回紹介したようなライブラリを使うと、もっといい感じ 面倒事は極力なくして、本質的なロジックの実装に注力したいですね
ありがとうございました