https://github.com/ufukhalis/rxdb
Reactive wrapper for JDBC calls.
https://github.com/ufukhalis/rxdb
database-driver jdbc reactive reactor
Last synced: about 1 month ago
JSON representation
Reactive wrapper for JDBC calls.
- Host: GitHub
- URL: https://github.com/ufukhalis/rxdb
- Owner: ufukhalis
- License: apache-2.0
- Created: 2019-06-28T13:23:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T23:26:15.000Z (about 4 years ago)
- Last Synced: 2025-08-14T15:48:36.275Z (6 months ago)
- Topics: database-driver, jdbc, reactive, reactor
- Language: Java
- Homepage:
- Size: 51.8 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ufukhalis/rxdb)
[](https://coveralls.io/github/ufukhalis/rxdb?branch=master)

[](https://gitter.im/rxdb-community/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

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.
io.github.ufukhalis
rxdb
0.3.0
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 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 resultFlux = database.select(selectSql);
.bindParameters(1)
.get();
Also you can create transactional query like below.
final String insertSql = "INSERT INTO REGISTER " + "VALUES (?, ?, ?, ?)";
Mono 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 result = database
.select(selectSql)
.get(TestEntity.class);
Also, if you would like to get only one result, you can use `findFirst` method.
Mono 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](./LICENSE).