+ - 0:00:00
Notes for current slide
Notes for next slide

Realm - Local

Mateu Yábar Valles

1 / 10
2 / 10

Realm

Realm is a fast, scalable alternative to SQLite with mobile to cloud data sync that makes building real-time, reactive mobile apps easy.

3 / 10

Realm

  • Base de dades nosql per aplicacions
  • Permet la sincronització amb Atlas MongoDB
4 / 10

Gradle

plugins {
(...)
id("io.realm.kotlin") version "1.5.0"
}
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("io.realm.kotlin:library-sync:1.5.0")
  • Assegurat usar Kotlin 1.7.21
5 / 10

Model

open class Item(
@PrimaryKey
var _id: ObjectId = ObjectId.create(),
var complete: Boolean = false,
var summary: String = "",
var owner_id: String = ""
) : RealmObject {
// Declaring empty contructor
constructor() : this(owner_id = "") {}
//var doAfter: RealmList<Item>? = realmListOf()
override fun toString() = "Item($_id, $summary)"
}
6 / 10

Configuració només local

val config = RealmConfiguration.Builder(setOf(Item::class))
.deleteRealmIfMigrationNeeded()
// .directory("customPath")
.build()
println("Realm Path: ${config.path}")
val realm = Realm.open(config)
7 / 10

Insertar

realm.writeBlocking {
val item = Item(summary = "Some summary ${Date()}"
// doAfter = query<Item>().find().take(2).toRealmList()
)
copyToRealm(item)
}
8 / 10

Consultar

val items = realm.query<Item>().find()
items.forEach { println(it.summary) }
9 / 10

Consultar - Flow

realm.query<Item>().find().asFlow().collect{
println(it.list.map{it.summary})
println()
}
launch {
repeat(3){
realm.writeBlocking {
val item = Item(summary = "Local Only Some summary ${Date()}")
copyToRealm(item)
}
delay(5000)
}
realm.close()
}
10 / 10
2 / 10
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow