Reactive extensions for SimpleNoSQL

Overview

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.
You might also like...
Clean Code and Reactive Programming PlayGround for Bangkit 2021

Clean Code and Reactive Programming PlayGround for Bangkit 2021 Hello! This repo contains the IntelliJ project that I use to present my talk, "Clean A

Simple Twitter Client just for tweeting, written in Kotlin with reactive MVVM-like approach
Simple Twitter Client just for tweeting, written in Kotlin with reactive MVVM-like approach

Monotweety Simple Twitter Client just for tweeting. Monotweety is also available at F-Droid compatible repository called IzzyOnDroid F-Droid Repositor

A sample skeleton backend app built using Spring Boot kotlin, Expedia Kotlin Graphql, Reactive Web that can be deployed to Google App Engine Flexible environmennt

spring-kotlin-gql-gae This is a sample skeleton of a backend app that was built using: Spring Boot(Kotlin) Reactive Web Sprinng Data R2DBC with MYSQL

My personal template for a Spring Boot REST reactive webapp

My personal spring boot kotlin reactive template Features Spring Security implementation with JWT access and refresh token MongoDB database Project Co

A project to learn about Reactive Microservices experimenting with architectures and patterns
A project to learn about Reactive Microservices experimenting with architectures and patterns

reactive-microservices-workshop Copyright © 2021 Aleix Morgadas - Licenced under CC BY-SA 4.0 A project to learn about Reactive Microservices experime

Veneer: reactive buttons for Jetpack Compose
Veneer: reactive buttons for Jetpack Compose

veneer reactive buttons for Jetpack Compose veneer is a library for reactive buttons. The buttons react depededing upon the roll, pitch and azimuth an

Reactive setup with Spring WebFlux , Kotlin, Postgres and Spring Data R2DBC

Reactive Spring with Kotlin and Pg Spring WebFlux with Netty instead of Spring Web with Tomcat Mono and Flux in all layers (controller, service, repo)

Ivy FRP is a Functional Reactive Programming framework for declarative-style programming for Android

FRP (Functional Reactive Programming) framework for declarative-style programming for Andorid. :rocket: (compatible with Jetpack Compose)

Event-driven application uses React, reactive Spring Boot WebFlux, R2DBC, MySQL and Liquibase

Product delivery Event-driven application uses React, reactive Spring Boot WebFlux, R2DBC, MySQL and Liquibase Status: IN PROGRESS if [[ "" != `docker

Android Maps Extensions is a library extending capabilities of Google Maps Android API v2.

Android Maps Extensions Library extending capabilities of Google Maps Android API v2. While Google Maps Android API v2 is a huge leap forward comapare

A collection of hand-crafted extensions for your Kotlin projects.

Splitties Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target). These libraries are intended to reduce the

A collection of hand-crafted extensions for your Kotlin projects.

Splitties Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target). These libraries are intended to reduce the

Kotlin extensions for Moshi, Make every thing you want with Moshi in just one line.

Kotlin extensions for Moshi, Make every thing with square / Moshi in one line.

Various experimental proposals and extensions to Javalin 4.x used in Reposilite 3.x

Javalin RFCs Various experimental extensions to Javalin 4.x used in Reposilite 3.x. Provides basic support for Kotlin coroutines and async routes with

🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.
🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.

🎁 Android Intent & Bundle extensions that insert and retrieve values elegantly.

Kotlin extensions, BindingAdapters, Composable functions for Android CameraX

Setup dependencies { implementation "com.github.skgmn:cameraxx:0.6.0" } Features CameraXX provides extensions methods for CameraX to use functions

Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.
Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Kotlin extensions of BlurHash for ImageView, Glide, Coil, Piccasso, and fast loading BlurHashDrawable optimized for Android.

Automatic CoroutineDispatcher injection and extensions for kotlinx.coroutines

Dispatch Utilities for kotlinx.coroutines which make them type-safe, easier to test, and more expressive. Use the predefined types and factories or de

Extensions to encrypt DataStore using Tink

encrypted-datastore Extensions to encrypt DataStore using Tink. ⚠️ This tiny library will be maintained until an official solution for DataStore encry

Comments
  • Can't access any method after bucket.newQuery()

    Can't access any method after bucket.newQuery()

    Hi! Thank you for nice lib, but I can't build project because every time I get error "Cannot access xxx method in ""com.xmartlabs.rxsimplenosql.Bucket.BucketQueryBuilder". Example: `class SampleBean implements Entity { private String name; private String id; private Map<String, Integer> 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, Integer> getMapping() {
        return mapping;
    }
    
    public void setMapping(Map<String, Integer> mapping) {
        this.mapping = mapping;
    }
    
    class sss{
        Bucket<SampleBean> bucket;
        public sss(Context context){
            Bucket<SampleBean> bucket = new Bucket<>(context, SampleBean.class, "bucketId");
        }
    
        public void 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();
        }
    }
    

    }` Have you any ideas what is the problem?

    opened by svarogSLASHc 1
  • Deleting multiple items not possible as described in the readme

    Deleting multiple items not possible as described in the readme

    Trying to delete multiple items from a bucket as described like this

    bucket.newQuery()
            .filter(sampleBean -> sampleBean.getName().startsWith("S"))
            .delete()
            .subscribe();
    

    will and cannot work, as the SimpleNoSQL documentation for the QueryBuilder#filter method already states that it will only be used when retrieving items from a bucket. Also if you look at the DataDispatcher class in the SimpleNoSQL project, you will see that in fact, it really just deletes either a single item or a whole bucket.

    This is my workaround (deltedItems is a list of items I want to delete, obviously):

     Completable completable = Completable.concat(
                                    Observable.from(deletedItems)
                                        .map(item -> localBucket
                                                        .newQuery()
                                                        .entityId(item.getId())
                                                        .delete()));
    return completable.andThen(Observable.just(true));
    
    opened by AlexGrafl 0
  • Use the cancel operation if necessary

    Use the cancel operation if necessary

    Something like the RxJava adapter for Retrofit: https://github.com/square/retrofit/blob/master/retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java#L139

    opened by bryant1410 0
  • Filter items in a reactive way

    Filter items in a reactive way

    Right now, the filter is not applied to an Observable. Maybe a better approach is that entities are directly got as Observables, and then a filter can be applied. So this should return an Observable instead: https://github.com/Jearil/SimpleNoSQL/blob/master/SimpleNoSQL/src/main/java/com/colintmiller/simplenosql/threading/DataDispatcher.java#L140

    opened by bryant1410 0
Owner
xmartlabs
xmartlabs
RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

RxJava: Reactive Extensions for the JVM RxJava is a Java VM implementation of Reactive Extensions: a library for composing asynchronous and event-base

ReactiveX 46.8k Jan 5, 2023
Pet project using Clean Architecture + MVVM + Reactive Extensions + Android Architecture Components. The data are fetched from LondonTheatreDirect API. 🎭

Theatre Pet project using Clean Architecture + MVVM + Reactive Extensions + Android Architecture Components. The data is fetched from LondonTheatreDir

André Mion 646 Jan 9, 2023
Gits-android-extensions - A collection of Kotlin extensions to simplify Android development

gits-android-extensions A collection of Kotlin extensions to simplify Android de

GITS Indonesia 3 Feb 3, 2022
Reactive Extension (Rx) Adaptor for Netty

Project Status 2018-02-014 1.0.x will be the RxNetty-2 update. It is currently pending an RFC for API changes. 0.5.x is the current release branch. Th

ReactiveX 1.4k Dec 27, 2022
A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.

SQL Brite A lightweight wrapper around SupportSQLiteOpenHelper and ContentResolver which introduces reactive stream semantics to queries. Deprecated T

Square 4.6k Jan 5, 2023
Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API

What is Postman? Postman is a reactive One-tap SMS verification library. This library allows the usage of RxJava with The SMS User Consent API Usage P

Cafer Mert Ceyhan 129 Dec 24, 2022
A reactive, interface-driven central role Bluetooth LE library for Android

RxCentralBle RxCentralBle provides a simple reactive paradigm for connecting to and communicating with Bluetooth LE peripherals from the central role.

Uber Open Source 198 Nov 29, 2022
A Kotlin library for reactive and boilerplate-free SharedPreferences in Android

KPreferences A Kotlin library for reactive and boilerplate-free Shared Preferences in Android. With KPreferences you can use Kotlin's marvelous delega

Mohamad Amin Mohamadi 19 Dec 16, 2020
A Kotlin Android library for content provider queries with reactive streams and coroutines.

Pickpocket An Android library for content provider queries with reactive streams and coroutines. Calendar Contacts SMS MMS Files/Media Call Log Bookma

Chris Basinger 27 Nov 14, 2022
Showcase project of Functional Reactive Programming on Android, using RxJava.

FunctionalAndroidReference FunctionalAndroidReference is a showcase project of Functional Reactive Programming on Android, using RxJava. It's a compan

Paco 278 Nov 18, 2022