Share
Embed
Transcript
39 slides
-
Evolution Evilution Repo Cache Database Network API 3.1 API 3.2
API 2.1 API 2.2 API 1.1 API 1.2 API xx API xx API xx API xx API xx API xx API xx API xx -
Realm Reactive Notifications Built-in Encryption Offline-First, Background Sync Object Schema
& Relationships Simple to Learn & Master Idiomatic Query Language -
Realm History • Free and Open Source Database • Founded
2011. First release in 2014 • C++ with Language SDK’s on top • Part of MongoDB since 2019 By MongoDB -
Realm Object Classes are the Schema class Dog : RealmObject
{ var name: String = "" var age: Int = 0 } class Person : RealmObject { var name: String = "" var dog: Dog? = null var puppies: RealmList<Expert> = RealmList() } @codeWithMohit -
Relationships class Person : RealmObject { var name: String =
"" var dog: Dog? = null var puppies: RealmList<Expert> = RealmList() var tags: RealmMap<String, Object> = RealmMap() var activities: RealmSet<String> = RealmSet() } @codeWithMohit -
Realm // Minimal configuration val config = RealmConfiguration.with(schema = setOf(Person::class,
Dog::class)) // Extended Configuration val config2 = RealmConfiguration.Builder(schema = setOf(Person::class, Dog::class)) .name("my-realm.realm") .deleteRealmIfMigrationNeeded() .build() // Opening a Realm val realm = Realm.open(config) // Closing a Realm (not strictly needed) realm.close() @codeWithMohit -
Realm // Minimal configuration val config = RealmConfiguration.with(schema = setOf(Person::class,
Dog::class)) // Extended Configuration val config2 = RealmConfiguration.Builder(schema = setOf(Person::class, Dog::class)) .name("my-realm.realm") .deleteRealmIfMigrationNeeded() .build() // Opening a Realm val realm = Realm.open(config) // Closing a Realm (not strictly needed) realm.close() @codeWithMohit -
Encryption & Schema Migration • Automatic Migration for basic use-case
like Addition or deletion. • Single call API for encrypting complete database. @codeWithMohit -
Realm // Minimal configuration val config = RealmConfiguration.with(schema = setOf(Person::class,
Dog::class)) // Extended Configuration val config2 = RealmConfiguration.Builder(schema = setOf(Person::class, Dog::class)) .name("my-realm.realm") .deleteRealmIfMigrationNeeded() .build() // Opening a Realm val realm = Realm.open(config) // Closing a Realm (not strictly needed) realm.close() @codeWithMohit -
Dependency Injection val koinModule = module { single { RealmConfiguration.with(schema
= setOf(Person::class)) } single { Realm.open(get()) } } class MyRepository : KoinComponent { val realm: Realm by inject() } @codeWithMohit -
Queries val id = "my-id" val realm: Realm by inject()
val results: RealmResults<Person> = realm.query<Counter>("id = ${id}") @codeWithMohit -
Realm Query Language • alwaysFalse • alwaysTrue • and •
beginGroup • beginsWith • between • contains • distinct • endsWith • endGroup • equalTo • greaterThan • greaterThanOrEqual • in • isEmpty • isNotEmpty • isNotNull • isNull • lessThan • lessThanOrEqual • like • limit • maximumDate • minimumDate • not • notEqualTo • or • sort • average • count • sum • max • min @codeWithMohit -
Listen for & React to changes in data val myPuppy
= realm.query<Dog>("age”, “1").first().find() // Observe Realm Notifications myDog.asFlow().map{ when(it){ is InitialResults -> TODO() is UpdatedResults -> TODO() } } // Update the puppy’s age to see the effect realm.write { myPuppy.age = 3 } @codeWithMohit -
Atlas Device Sync Out of the box device-cloud synchronization Atlas
Database Atlas Device Sync Mobile App @codeWithMohit -
Sync Conflict Resolution Offline client deletes User1 Driver adds User3
and updates User2’s number t0 t1 Sync Changes t2 Sync Changes t2 Send Merged Changes t4 Send Merged Changes t4 Apply Conflict Resolution Rules t3 Delete Always Wins MongoDB Device Sync Last Update Wins Inserts in lists are ordered by time MongoDB Atlas Realm Sync Client Final State User List |- user0 : 000 |- user2 : 999 |- user3 : 003 Initial State User List |- user0 : 000 |- user1 : 001 |- user2 : 002 -
Thatʼs not all ! Out-of-the-box device-cloud synchronization Mobile-optimized database Ultra-lightweight
and fast Object-oriented No ORM or DAO required Advanced security and permissions Built-in conflict resolution The leading developer data platform on the cloud Functions Triggers GraphQL DataAPI Data Access Control Atlas Realm Kotlin SDK Atlas Device Sync Search Charts Time Series @codewithMohit