Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
![EdgeDB Java](./branding/banner.png)
![Gel Java](./branding/banner.png)

<div align="center">
<h1>☕ The official Java/JVM client library for EdgeDB ☕</h1>
<h1>☕ The official Java/JVM client library for Gel ☕</h1>

<a href="https://github.com/edgedb/edgedb-java/actions" rel="nofollow">
<img src="https://github.com/edgedb/edgedb-java/actions/workflows/gradle.yml/badge.svg?event=push&branch=master" alt="Build status">
<a href="https://github.com.gel/edgedb-java/actions" rel="nofollow">
<img src="https://github.com.gel/edgedb-java/actions/workflows/gradle.yml/badge.svg?event=push&branch=master" alt="Build status">
</a>
<a href="https://github.com/edgedb/edgedb/blob/master/LICENSE">
<a href="https://github.com.gel/edgedb/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-Apache%202.0-blue" />
</a>
<a href="https://discord.gg/edgedb">
Expand All @@ -20,13 +20,13 @@ The Java binding is distrubuted via maven central:

#### Gradle
```groovy
implementation 'com.edgedb:driver:0.3.0'
implementation 'com.gel:driver:0.3.0'
```

#### Maven
```xml
<dependency>
<groupId>com.edgedb</groupId>
<groupId>com.gel</groupId>
<artifactId>driver</artifactId>
<version>0.3.0</version>
</dependency>
Expand All @@ -36,36 +36,36 @@ implementation 'com.edgedb:driver:0.3.0'

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

## Usage

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

```java
import com.edgedb.driver.EdgeDBClient;
import com.gel.driver.GelClientPool;

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

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

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

```java
import com.edgedb.driver.EdgeDBClient;
import com.gel.driver.GelClientPool;
import reactor.core.publisher.Mono;

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

Mono.fromFuture(client.querySingle(String.class, "SELECT 'Hello, Java!'"))
Mono.fromFuture(clientPool.querySingle(String.class, "SELECT 'Hello, Java!'"))
.doOnNext(System.out::println)
.block();
}
Expand All @@ -75,15 +75,15 @@ This also means it plays nicely with other JVM language that support asynchronou

```kotlin

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

fun main() {
val client = EdgeDBClient()
val clientPool = GelClientPool()

runBlocking {
client.querySingle(String::class.java, "SELECT 'Hello, Kotlin!'")
clientPool.querySingle(String::class.java, "SELECT 'Hello, Kotlin!'")
.thenAccept { println(it) }
.await()
}
Expand All @@ -92,20 +92,20 @@ fun main() {

```scala

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

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

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

## Examples
Some examples of using the Java client api can be found in the [examples](./examples) directory.
Some examples of using the Java clientPool api can be found in the [examples](./examples) directory.

## Compiling
This project uses gradle. To build the project run the following command:
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ ext {
project_version = '0.3.1-SNAPSHOT'
github_org = 'edgedb'
project_name = 'edgedb-java'
artifact_group = 'com.edgedb'
project_description = 'Java binding for the EdgeDB database'
artifact_group = 'com.gel'
project_description = 'Java binding for Gel'
project_url = "https://edgedb.com"
project_jdk = '11'
jdk = JavaVersion.current().majorVersion
Expand Down Expand Up @@ -103,7 +103,7 @@ allprojects {
}

subprojects {
archivesBaseName = "com.edgedb.$project.name"
archivesBaseName = "com.gel.$project.name"

tasks.withType(Javadoc).configureEach {
title = "$archivesBaseName ${version} API"
Expand Down
2 changes: 1 addition & 1 deletion dbschema/futures.esdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Disable the application of access policies within access policies
# themselves. This behavior will become the default in EdgeDB 3.0.
# themselves. This behavior will become the default in Gel 3.0.
# See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
using future nonrecursive_access_policies;
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = 'edgedb'
copyright = '2019-present MagicStack Inc. and the EdgeDB authors.'
author = 'MagicStack Inc. and the EdgeDB authors'
project = 'gel'
copyright = '2019-present MagicStack Inc. and the Gel authors.'
author = 'MagicStack Inc. and the Gel authors'


# The full version, including alpha/beta/rc tags
Expand Down
18 changes: 9 additions & 9 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
.. _edgedb-java-configuration:
.. _gel-java-configuration:

=============
Configuration
=============

The driver can be configured by passing an ``EdgeDBClientConfig`` object
into the ``EdgeDBClient`` constructor. The client config contains immutable
settings for client behavior. You can construct a new ``EdgeDBClientConfig``
The driver can be configured by passing an ``GelClientConfig`` object
into the ``GelClientPool`` constructor. The client config contains immutable
settings for client behavior. You can construct a new ``GelClientConfig``
with the builder subclass like so:

.. code-block:: java

var builder = EdgeDBClientConfig.builder();
var builder = GelClientConfig.builder();

..

Expand All @@ -30,7 +30,7 @@ These are the following methods exposed on the configuration builder:
+------------------------------+-------------------------+---------------------------------------------------------------------------------------------+
| ``withConnectionTimeout`` | ``long``, ``TimeUnit`` | The amount of time to wait for a connection to be established. |
+------------------------------+-------------------------+---------------------------------------------------------------------------------------------+
| ``withMessageTimeout`` | ``long, TimeUnit`` | The amount of time to wait for an expected response from EdgeDB. |
| ``withMessageTimeout`` | ``long, TimeUnit`` | The amount of time to wait for an expected response from Gel. |
+------------------------------+-------------------------+---------------------------------------------------------------------------------------------+
| ``withExplicitObjectIds`` | ``boolean`` | Whether or not the ``id`` property of objects need to be explicitly included in shapes. |
+------------------------------+-------------------------+---------------------------------------------------------------------------------------------+
Expand All @@ -50,7 +50,7 @@ These are the following methods exposed on the configuration builder:
+------------------------------+-------------------------+---------------------------------------------------------------------------------------------+

This configuration object can then be passed into the constructor of
a ``EdgeDBClient``.
a ``GelClientPool``.

In addition to client-level configuration, the driver offers session-level
configuration. This type of configuration is controlled using methods prefixed
Expand All @@ -59,8 +59,8 @@ connection, pool, and client configuration.

.. code-block:: java

var client = new EdgeDBClient();
var clientPool = new GelClientPool();

var appliedGlobalClient = client.withGlobals(new HashMap<>(){{
var appliedGlobalClient = clientPool.withGlobals(new HashMap<>(){{
put("current_user_id", ...);
}});
135 changes: 49 additions & 86 deletions docs/connecting.rst
Original file line number Diff line number Diff line change
@@ -1,106 +1,69 @@
.. _edgedb_java_connecting:
.. _gel_java_connecting:

=====================
Connection Parameters
=====================

The ``EdgeDBClient`` constructor can consume an ``EdgeDBConnection`` class
containing connection arguments for the client.
The ``GelClientPool`` constructor can optionally consume a ``GelConnection``
object containing connection arguments for the client.

Most of the time, the connection arguments are implicitly resolved via
:ref:`projects <ref_intro_projects>`. In other cases, the ``EdgeDBConnection``
:ref:`projects <ref_intro_projects>`. In other cases, the ``GelConnection``
class exposes ways to construct connection arguments.

Connection builder
------------------

You can use a provided builder by calling the ``builder()`` method on
``EdgeDBConnection``
``GelConnection``

.. code-block:: java

var builder = EdgeDBConnection.builder();
var builder = GelConnection.builder();
var connection = builder.build();

The builder has the following methods:

+---------------------+-----------------+-----------------------------------------------------------------------+
| Name | Type | Description |
+=====================+=================+=======================================================================+
| ``withUser`` | String | The username to connect as. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withPassword`` | String | The password used to authenticate. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withDatabase`` | String | The name of the database to use. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withHostname`` | String | The hostname of the database. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withPort`` | int | The port of the database. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withTlsca`` | String | The TLS certificate authority, used to verify the server certificate. |
+---------------------+-----------------+-----------------------------------------------------------------------+
| ``withTlsSecurity`` | TLSSecurityMode | The TLS security policy. |
+---------------------+-----------------+-----------------------------------------------------------------------+


Parse & constructor methods
---------------------------

``EdgeDBConnection`` also exposes static methods used to parse connection
arguments from different sources.

fromDSN
^^^^^^^

This method parses a :ref:`DSN <ref_dsn>` string into an ``EdgeDBConnection``.

.. code-block:: java

var connection = EdgeDBConnection
.fromDSN("edgedb://user:pass@host:port/db");

fromProjectFile
^^^^^^^^^^^^^^^

This method resolves connection arguments from an ``edgedb.toml``
:ref:`project file <ref_intro_projects>`.

.. code-block:: java

var connection = EdgeDBConnection
.fromProjectFile("~/myproject/edgedb.toml");
The builder accepts several `parameters <https://docs.edgedb.com/database/reference/connection>`_
which are used to construct the final ``GelConnection``.

fromInstanceName
^^^^^^^^^^^^^^^^
If no parameters are provided, the default behavior is to search for the
project's ``gel.toml`` file.

This method resolves the connection arguments for a given instance name.

.. code-block:: java

var connection = EdgeDBConnection
.fromInstanceName("my_instance_name");

resolveEdgeDBTOML
^^^^^^^^^^^^^^^^^

This method is the default behaviour, it scans the current directory for
a ``edgedb.toml`` project file, if none is found, the parent directory is
scanned recursivly until a project file is found; if none is found, a
``FileNotFoundException`` is raised.

.. code-block:: java

var connection = EdgeDBConnection
.resolveEdgeDBTOML();

parse
^^^^^

The parse method will resolve the given arguments as well as apply
environment variables to the connection, following the
:ref:`priority levels <ref_reference_connection_priority>` of arguments.

.. code-block:: java

var connection = EdgeDBConnection
.parse("my_instance");
The builder has the following methods:

+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| Name | Type | Description |
+=====================================+==========================+=========================================================================+
| ``withInstance`` | String | The name of the gel instance to connect to. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withDsn`` | String | The DSN to connect to. See: `here <https://www.edgedb.com/docs/reference/dsn>`_ for more information. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withCredentials`` | String | A json representation of the connection arguments. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withCredentialsFile`` | Path | A file to read as the credentials. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withHost`` | String | The hostname to connect as. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withPort`` | int | The port of the database. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withBranch`` | String | The name of the branch to use. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withDatabase`` | String | The name of the database to use. (Deprecated in favor of withBranch) |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withUser`` | String | The username to connect as. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withPassword`` | String | The password used to authenticate. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withSecretKey`` | String | The secret key used to use for cloud connections. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withTLSCertificateAuthority`` | String | The TLS certificate authority, used to verifiy the server certificate. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withTLSCertificateAuthorityFile`` | Path | A file to read as the TLS certificate authority. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withTlsSecurity`` | TLSSecurityMode | The TLS security policy. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withTLSServerName`` | String | The TLS server name to use. Overrides the hostname. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withWaitUntilAvailable`` | WaitTime | The time to wait for a connection to the server to be established. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
| ``withServerSettings`` | HashMap<String, String> | Additional settings for the server connection. Currently has no effect. |
+-------------------------------------+--------------------------+-------------------------------------------------------------------------+
Loading
Loading