rx-realm
mulab
58
Visit GitHub RepoNoSQL

** Deprecated! From realm-java 0.87.0 and on, it has builtin observable support **

Android Arsenal Build Status

rx-realm

A lightweight wrapper around realm-java which introduces reactive stream semantics to SQL operations.(Inspired by square/sqlbrite)

Setup

Add the JitPack repository to your build file:

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

Add the dependency:

dependencies {
    compile 'com.github.mulab:rx-realm:1.2.0'
    compile 'io.realm:realm-android:0.86.1'
}

Initialize (in Appliction#onCreate method for Android App):

RealmConfiguration config = new RealmConfiguration.Builder(context)
    // set configuration for realm, see realm-java's document
    .build();
RealmDatabase.init(config);

Usages

Assume that Foo is a realm data model, i.e. Foo extends RealmObject.(see more in Realm-java's documentation)

Query

RealmDatabase.createQuery(new Query()<Foo>{
    @Override
    public RealmResults<Foo> call(Realm realm) {
        return realm.where(Foo.class).findAll();
    }
}, Foo.class).subscribe(this);

The last parameter of createQuery means watching on Foo if it is notified.

Exec

RealmDatabase.exec(new Exec() {
    @Override
    public void run(Realm realm) {
        realm.where(Foo.class).findAll().clear();
    }
}, Foo.class).subscribe(this);

The last parameter of exec means it will notify Foo.

Join India's largest learning revolution
Free Video Tutorials
Learn Programming
Learning is a journey, let's learn together

MindOrks Newsletter
100,000+ Subscribers
A free weekly newsletter that comes with the latest Android articles, open source projects, events and hot discussions.

Subscribe Now

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

OUR LEARNERS WORK AT