RxAndroidOrm

RxAndroidOrm is a reactive simple & fluent Android ORM (RxJava2 ready)

Download

dependencies {
    compile 'com.github.florent37:rxandroidorm:1.0.1'
    provided 'com.github.florent37:rxandroidorm-annotations:1.0.1'
    annotationProcessor 'com.github.florent37:rxandroidorm-compiler:1.0.1'
}

A simple & fluent Android ORM, how can it be easier ?
And it’s compatible with RxJava2 !

Observable.fromArray(
                new Computer(Computer.WINDOWS, "MasterRace", Arrays.asList(new Software("Photoshop"))),
                new Computer(Computer.WINDOWS, "Gamerz"),
                new Computer(Computer.LINUX, "MasterRace", Arrays.asList(new Software("Gimp"))))
                .flatMap(computerDb::add)
                .subscribe();

Observable.just(new Computer(Computer.MAC, "Mac Mini"))
                .flatMap(computerDb::add)
                .doOnNext(computer -> computer.getSoftwares().add(new Software("Photoshop")))
                .flatMap(computerDb::update)
                .subscribe();

computerDb.select()
                .label().equalsTo("MasterRace")
                .or()
                .softwares(SoftwareDatabase.where().name().equalsTo("Photoshop"))

                .asObservable()
                .subscribe(computers -> Log.d(TAG, computers.toString()));

First, initialize !

Don’t forget to initialise RxAndroidOrm in your applicarion:

public class MyApplicarion extends Applicarion {

    @Override public void onCreate() {
        super.onCreate();
        RxAndroidOrm.onCreate(this);
    }

}

Second, annotate your models

Use Annotations to mark classes to be persisted:

@Model
public class Computer {

    @Id long id;
    String name;
   
    List<Software> softwares;
}

Logging

You can log all SQL queries from entities managers:

computerDb.logQueries((query, datas) -> Log.d(TAG, query) }

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *