Code Monkey home page Code Monkey logo

kmp-realm's Introduction

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")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.