AndroidScalaJavaJVM Drivers

Fauna’s open source JVM driver supports languages that run in the Java Virtual Machine. Currently, Java, Android and Scala clients are implemented.

Features

  • All drivers fully support the current version of the FQL API.

  • Java and Scala clients share the same underlying library faunadb-common.

  • Java and Android clients share the same DSL library faunadb-java-dsl.

  • Supports Dropwizard Metrics hooks for stats reporting (except Android).

  • Supports Android 8.0 (API level 26)

Documentation

Javadocs and Scaladocs are hosted on GitHub:

Detailed documentation is available for these languages:

Dependencies

Shared

Android

Java

  • Java 8

  • Java 11

Scala

  • Scala 2.11.x

  • Scala 2.12.x

Install

Android

Download from the Maven central repository:

faunadb-android/pom.xml:
  <dependencies>
  ...
  <dependency>
    <groupId>com.faunadb</groupId>
    <artifactId>faunadb-android</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
  </dependency>
  ...
</dependencies>

Java

Download from the Maven central repository:

faunadb-java/pom.xml:
  <dependencies>
  ...
  <dependency>
    <groupId>com.faunadb</groupId>
    <artifactId>faunadb-java</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
  </dependency>
  ...
</dependencies>

Scala

faunadb-scala/sbt:
libraryDependencies += ("com.faunadb" %% "faunadb-scala" % "2.6.1")

Usage

Java or Android

import com.faunadb.client.FaunaClient;

import static com.faunadb.client.query.Language.*;

/**
 * This example connects to FaunaDB Cloud using the secret provided
 * and creates a new database named "my-first-database"
 */
public class Main {
    public static void main(String[] args) throws Exception {

        //Create an admin connection to FaunaDB.
        FaunaClient adminClient =
            FaunaClient.builder()
                .withSecret("put-your-key-secret-here")
                .build();

        adminClient.query(
            CreateDatabase(
                Obj("name", Value("my-first-database"))
            )
        ).get();

        client.close();
    }
}

Scala

import faunadb._
import faunadb.query._
import scala.concurrent._
import scala.concurrent.duration._

/**
  * This example connects to FaunaDB Cloud using the secret provided
  * and creates a new database named "my-first-database"
  */
object Main extends App {

  import ExecutionContext.Implicits._

  val client = FaunaClient(
    secret = "put-your-secret-here"
  )

  val result = client.query(
    CreateDatabase(
      Obj("name" -> "my-first-database")
    )
  )

  Await.result(result, Duration.Inf)

  client.close()
}

Next steps

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!