GithubHelp home page GithubHelp logo

isabella232 / rxsimplenosql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xmartlabs/rxsimplenosql

0.0 0.0 0.0 73 KB

Reactive extensions for SimpleNoSQL

License: Apache License 2.0

Java 100.00%

rxsimplenosql's Introduction

RxSimpleNoSQL

Reactive extensions for SimpleNoSQL. Manipulate entities using Observables and Completables.

Examples

Suppose we have the following entity we want to manipulate:

class SampleBean implements Entity {
    private String name;
    private String id;
    private Map<String, String> mapping;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Map<String, String> getMapping() {
        return mapping;
    }

    public void setMapping(Map<String, String> mapping) {
        this.mapping = mapping;
    }
}

We first start creating a bucket:

Bucket<SampleBean> bucket = new Bucket<>(context, SampleBean.class, "bucketId");

Save

Single

SampleBean entity = new SampleBean();
entity.setId("1");
entity.setName("Colin");
Map<String, Integer> birthday = new HashMap<String, Integer>();
birthday.put("day", 17);
birthday.put("month", 2);
birthday.put("year", 1982);
entity.setMapping(birthday);

bucket.newQuery()
        .save(entity)
        .subscribe();

Multiple

SampleBean entity2 = new SampleBean();
entity2.setId("2");
entity2.setName("Santiago");

SampleBean entity3 = new SampleBean();
entity3.setId("3");
entity3.setName("Xmartlabs");

bucket.newQuery()
        .save(Arrays.asList(entity2, entity3))
        .subscribe();

Retrieve

Single

bucket.newQuery()
        .entityId("entityId")
        .retrieve()
        .subscribe(sampleBean -> System.out.println("Name: %s", sampleBean.getName()));

Multiple

bucket.newQuery()
        .filter(sampleBean -> sampleBean.getName().startsWith("S"))
        .retrieve()
        .subscribe(sampleBean -> System.out.println("Name: %s", sampleBean.getName()));

All

bucket.newQuery()
        .retrieve()
        .subscribe(sampleBean -> System.out.println("Name: %s", sampleBean.getName()));

Delete

Single

bucket.newQuery()
        .entityId("entityId")
        .delete()
        .subscribe();

Multiple

Currently, SimpleNoSQL does not support the usage of filter for the delete operation. There's an issue opened.

Nevertheless, this functionality can be achieved by first retrieving the entities to be deleted and then performing the actual delete operation individually:

Observable<SampleBean> itemsToDelete = bucket.newQuery()
        .filter(sampleBean -> sampleBean.getName().startsWith("S"))
        .retrieve()

Completable deleteCompletable = Completable.concat(
                                  itemsToDelete
                                      .map(item -> bucket.newQuery()
                                                      .entityId(item.getId()))
                                                      .delete());

All

bucket.newQuery()
        .delete()
        .subscribe();

Sorting

[As SimpleNoSQL sorts the results in memory] (https://github.com/Jearil/SimpleNoSQL/blob/master/SimpleNoSQL/src/main/java/com/colintmiller/simplenosql/threading/DataDispatcher.java#L140), you can carry this out the same way with Observable#toSortedList.

Development

As SimpleNoSQL, this project still isn't stable (the API can change at any time). You can use it with Gradle and JitPack:

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

Then adding the dependency:

implementation 'com.github.xmartlabs:RxSimpleNoSQL:-SNAPSHOT'

RxSimpleNoSQL requires at minimum Java 7 or Android 2.2.

Build

Build Status

To build:

git clone https://github.com/xmartlabs/RxSimpleNoSQL.git
cd RxSimpleNoSQL/
./gradlew build

License

Copyright 2016 Xmartlabs SRL.

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.

rxsimplenosql's People

Contributors

ardacebi avatar bryant1410 avatar diegomedina248 avatar

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.