Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
/ kmp-realm Public archive
generated from Tweener/kmplate-lib

kmp-realm a Kotlin Multiplaform library which wraps Kotlin Realm with pre-configuration.

Notifications You must be signed in to change notification settings

Tweener/kmp-realm

Repository files navigation

Warning

This repository is no longer supported or updated. It has been migrated as part of a BoM here: kmp-realm.

kmp-realm

kmp-realm a Kotlin Multiplaform library which wraps Kotlin Realm with pre-configuration.

💾 Installation

1️⃣ Add the dependency in the sourceSet of all modules that require Realm:

implementation('io.github.tweener:kmp-realm:$kmp-realm_version')

The latest version is:

2️⃣ Add the Realm plugin dependency to the root's build.gradle.kts:

id("io.realm.kotlin").version("1.13.0").apply(false)

3️⃣ Apply the Realm plugin to all modules that declare RealmObjects:

id("io.realm.kotlin")

⚙️ Usage

1️⃣ Configure your database schema by specifying all your RealmObjects:

val realmDatabse = RealmDatabase(
  schema = setOf(
    // Here, add all your classes that extend `RealmObject`
    RealmUserModel::class, // This is an example. RealmUserModel extends RealmObject
    ...
  )
)

2️⃣ Use the methods from RealmDatabase class to interact with your Realm database:

// Get all users synchronously
realmDatabase.getAll<RealmUserModel>()

// Get all users asynchronously, using Kotlin Flows
realmDatabase.getAllAsFlow<RealmUserModel>()

// Find by property
realmDatabase.findByProperty(propertyName = "name", propertyValue = "John")

// Find by Realm UUID
realmDatabase.findByRealmUuid(uuid = "f826c548-fec7-4409-bdfb-523f29383857")

// Insert a new model or update an existing one
realmDatabase.upsert(user)

// Delete a model
realmDatabase.deleteById(id = "user1234")

About

kmp-realm a Kotlin Multiplaform library which wraps Kotlin Realm with pre-configuration.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages