rxdb

Reactive library for JDBC calls

Лицензия

Лицензия

Группа

Группа

io.github.ufukhalis
Идентификатор

Идентификатор

rxdb
Последняя версия

Последняя версия

0.3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

rxdb
Reactive library for JDBC calls
Ссылка на сайт

Ссылка на сайт

https://github.com/ufukhalis/rxdb
Система контроля версий

Система контроля версий

https://github.com/ufukhalis/rxdb/tree/master

Скачать rxdb

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.github.ufukhalis/rxdb/ -->
<dependency>
    <groupId>io.github.ufukhalis</groupId>
    <artifactId>rxdb</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.ufukhalis/rxdb/
implementation 'io.github.ufukhalis:rxdb:0.3.0'
// https://jarcasting.com/artifacts/io.github.ufukhalis/rxdb/
implementation ("io.github.ufukhalis:rxdb:0.3.0")
'io.github.ufukhalis:rxdb:jar:0.3.0'
<dependency org="io.github.ufukhalis" name="rxdb" rev="0.3.0">
  <artifact name="rxdb" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.ufukhalis', module='rxdb', version='0.3.0')
)
libraryDependencies += "io.github.ufukhalis" % "rxdb" % "0.3.0"
[io.github.ufukhalis/rxdb "0.3.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
io.vavr : vavr jar 0.10.0
io.projectreactor : reactor-core jar 3.2.10.RELEASE
org.slf4j : slf4j-api jar 1.7.26

test (3)

Идентификатор библиотеки Тип Версия
io.projectreactor : reactor-test jar 3.2.10.RELEASE
com.h2database : h2 jar 1.4.196
org.junit.jupiter : junit-jupiter jar 5.4.2

Модули Проекта

Данный проект не имеет модулей.

Build Status Coverage Status Maven Central Join the chat at https://gitter.im/sahat/hackathon-starter

Alt text

RXDB

A reactive library option for JDBC calls. In the background, it uses Reactor library (https://projectreactor.io).

How to Use

Firstly, you should add latest rxdb dependency to your project.

<dependency>
    <groupId>io.github.ufukhalis</groupId>
    <artifactId>rxdb</artifactId>
    <version>0.3.0</version>
</dependency>

Then you need to add jdbc driver for your database which you want to connect.

After, adding dependencies, you can create an instance from Database class.

Database database = new Database.Builder()
        .maxConnections(5) // Default 10
        .minConnections(2) // Default 5
        .periodForHealthCheck(Duration.ofSeconds(5)) // Default 5 seconds
        .jdbcUrl("jdbc:h2:~/test") // In-memory db
        .healthCheck(HealthCheck.H2) // Default HealthCheck.OTHER
        .build();

Using Database instance, you can send queries to your database.

Inserting a record to the table.

final String insertSql = "INSERT INTO table_name VALUES (?, ?, ?, ?)";
Mono<Integer> resultMono = database.update(insertSql)
        .bindParameters(1, "Ufuk", "Halis", 28)
        .get();

Fetching records from the table.

final String selectSql = "select * from table_name where id=?";
Flux<ResultSet> resultFlux = database.select(selectSql);
        .bindParameters(1)
        .get();

Also you can create transactional query like below.

final String insertSql = "INSERT INTO REGISTER " + "VALUES (?, ?, ?, ?)";

Mono<Boolean> result = database.tx(insertSql)
        .bindParameters(3, "ufuk", "halis", 28, 4, "bob", "dylan", 34)
        .get();

In the above code, insertSql query will try to run two times regarding parameters to bindParameters method. If an error occurs, it will throw an exception and changes will be rollback.

You can also map your records directly to Java Object too. Firstly, you should add @Column annotation to your pojo class like below.

public class TestEntity {
    @Column(value = "id")
    private int id;

    @Column(value = "first")
    private String first;

    @Column(value = "last")
    private String last;

    @Column(value = "age")
    private int age;
    
    // Getters and Setters
}

After, you can use your database instance like below.

Flux<TestEntity> result = database
                .select(selectSql)
                .get(TestEntity.class);

Also, if you would like to get only one result, you can use findFirst method.

Mono<TestEntity> result = database
                .select(selectSql)
                .findFirst(TestEntity.class);

Note

This project is still under development. But you can use in your projects.

For more information about Project Reactor, check the site https://projectreactor.io

For more information about vavr.io, check the site http://vavr-io.github.io

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENCE.

Версии библиотеки

Версия
0.3.0
0.2.0
0.1.0
0.0.1