Java client library for EdgeDB
This is the official EdgeDB Java client, available to other JVM languages as well.
Quickstart
To get started, you will need to setup an EdgeDB project and have an instance created. For more information regarding how to do this, we recommend going through the Quickstart guide.
Once you have an instance running, you can add the driver dependency to your project.
Maven
Gradle
Copy
<dependency>
<groupId>com.edgedb</groupId>
<artifactId>driver</artifactId>
</dependency>
Copy
implementation 'com.edgedb:driver'
Once you have the dependency added, you can start using the client. The following is a simple example of how to connect to an EdgeDB instance and execute a query:
Futures
Reactor
Copy
import com.edgedb.driver.EdgeDBClient;
import java.util.concurrent.CompletableFuture;
public class Main {
public static void main(String[] args) {
var client = new EdgeDBClient();
client.querySingle(String.class, "SELECT 'Hello, Java!'")
.thenAccept(System.out::println)
.toCompletableFuture().get();
}
}
Copy
import com.edgedb.driver.EdgeDBClient;
import reactor.core.publisher.Mono;
public class Main {
public static void main(String[] args) {
var client = new EdgeDBClient();
Mono.fromFuture(client.querySingle(String.class, "SELECT 'Hello, Java!'"))
.doOnNext(System.out::println)
.block();
}
}
You can represent schema types with classes, reflecting the properties/links in the schema type:
Code
Schema 2.x
Schema 3+
Copy
@EdgeDBType
public class Person {
public String name;
public int age;
}
..
client.query(Person.class, "SELECT Person { name, age }")
.thenAccept(result -> {
for(var person : result) {
System.out.println("Person { " + person.name + ", " + person.age + "}");
}
});
Copy
module default {
type Person {
property name -> str;
property age -> int32;
}
}
Copy
module default {
type Person {
name: str;
age: int32;
}
}
Learn more about data modeling.