Giter Site home page Giter Site logo

florent37 / rxandroidorm Goto Github PK

View Code? Open in Web Editor NEW
36.0 4.0 7.0 146 KB

An reactive simple & fluent Android ORM, how can it be easier ? RxJava2 ready

License: Apache License 2.0

Java 99.94% Shell 0.06%
rxjava database sql orm orma android java sqllite xml annotations proxy reactive react observable

rxandroidorm's Introduction

RxAndroidOrm

Android app on Google Play

Download

Buy Me a Coffee at ko-fi.com

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

TODO

  • Enum support

Credits

Author: Florent Champigny http://www.florentchampigny.com/

Blog : http://www.tutos-android-france.com/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2017 Florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

rxandroidorm's People

Contributors

florent37 avatar tspoke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rxandroidorm's Issues

Cannot get 1.0.1

Hi @florent37,

I can't get the library v1.0.1 on gradle anymore. There is probably an issue in your publish conf.

Error:Failed to resolve: annotationProcessor

Another issue

It looks like the Database interface added in #2 (and all the static java files) are not generated if there is no @model annotations in models. I didn't see it yesterday. It could be interesting to generate these files no matter if this annotation is used.
IMHO, these statics java classes could be created in your library directly (and not generated) to improve maintainability.

Thank you ;)

Parent interface on databases

Hi Florent,

I wanted to implements a version of store2store with your orm. For now I have an issue with your generated code of ObjectDatabase.

To extends and use correctly your library a common interface between databases is needed.

Something like :

public interface Database<T> {
    QueryBuilder select(final T object);    
    
    Observable<T> add(final T object);

    Observable<List<T>> add(final List<T> objects);

    Observable<T> update(final T object);

    Observable<List<T>> update(final List<T> objects);

    Observable<Boolean> exists(SQLiteDatabase db, final T object); // It should be possible to remove the SQLiteDatabase param here :)

    Observable<Boolean> delete(final T object);

    Observable<Boolean> delete(final List<T> objects);

    Observable<Boolean> deleteAll();

    Observable<Integer> count();
}

Then in the generated class :

public class ComputerDatabase extends Database<Computer> {
 // ...
}

Let the generated Databases classes implementing this interface could help us to abstract a little bit more our code and do not depends on concretes classes.

If you want me to do a pull request for that, let me know ;)

Thank you,
Thibaud.

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.