edgedb / edgedb-java

The official Java client library for EdgeDB
Apache License 2.0
19 stars 4 forks source link

EdgeDB Java

☕ The official Java/JVM client library for EdgeDB ☕

Build status Discord

Installation

The Java binding is distrubuted via maven central:

Gradle

implementation 'com.edgedb:driver:0.3.0'

Maven

<dependency>
  <groupId>com.edgedb</groupId>
  <artifactId>driver</artifactId>
  <version>0.3.0</version>
</dependency>

SBT

libraryDependencies ++= Seq(
  "com.edgedb" % "driver" % "0.3.0"
)

Usage

The EdgeDBClient class contains all the methods necessary to interact with the EdgeDB database.

import com.edgedb.driver.EdgeDBClient;

void main() {
    var client = new EdgeDBClient();

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

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

import com.edgedb.driver.EdgeDBClient;
import reactor.core.publisher.Mono;

void main() {
    var client = new EdgeDBClient();

    Mono.fromFuture(client.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.edgedb.driver.EdgeDBClient
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking

fun main() {
    val client = EdgeDBClient()

    runBlocking {
        client.querySingle(String::class.java, "SELECT 'Hello, Kotlin!'")
            .thenAccept { println(it) }
            .await()
    }
}

import com.edgedb.driver.EdgeDBClient
import scala.jdk.FutureConverters.*

object Main extends App {
  val client = new EdgeDBClient()

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

Examples

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

Compiling

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

./gradlew build