Skip to content

geldata/gel-java

Repository files navigation

Gel Java

☕ The official Java/JVM client library for Gel ☕

Build status Discord

Installation

The Java binding is distrubuted via maven central:

Gradle

implementation 'com.gel:driver:0.4.0'

Maven

<dependency>
  <groupId>com.gel</groupId>
  <artifactId>driver</artifactId>
  <version>0.4.0</version>
</dependency>

SBT

libraryDependencies ++= Seq(
  "com.gel" % "driver" % "0.4.0"
)

Usage

The GelClientPool class contains all the methods necessary to interact with the Gel database.

import com.gel.driver.GelClientPool;

void main() {
    var clientPool = new GelClientPool();

    clientPool.query(String.class, "SELECT 'Hello, Java!'")
        .thenAccept(System.out::println);
}

The GelClientPool uses CompletionStage for asynchronous operations, allowing you to integrate it with your favorite asynchronous frameworks

import com.gel.driver.GelClientPool;
import reactor.core.publisher.Mono;

void main() {
    var clientPool = new GelClientPool();

    Mono.fromFuture(clientPool.querySingle(String.class, "SELECT 'Hello, Java!'"))
        .doOnNext(System.out::println)
        .block();
}

This also means it plays nicely with other JVM language that support asynchronous programming via CompletionStage

import com.gel.driver.GelClientPool
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking

fun main() {
    val clientPool = GelClientPool()

    runBlocking {
        clientPool.querySingle(String::class.java, "SELECT 'Hello, Kotlin!'")
            .thenAccept { println(it) }
            .await()
    }
}
import com.gel.driver.GelClientPool
import scala.jdk.FutureConverters.*

object Main extends App {
  val clientPool = new GelClientPool()

  clientPool.querySingle(classOf[String], "SELECT 'Hello, Scala!'")
    .asScala
    .map(println)
}

Examples

Some examples of using the Java clientPool api can be found in the examples directory.

Compiling

This project uses gradle. To build the project run the following command:

./gradlew build