All Projects → fauna → Faunadb Jvm

fauna / Faunadb Jvm

Licence: other
Scala and Java driver for FaunaDB

Programming Languages

java
68154 projects - #9 most used programming language
scala
5932 projects

Projects that are alternatives of or similar to Faunadb Jvm

Faunadb Go
Go driver for FaunaDB
Stars: ✭ 140 (+180%)
Mutual labels:  database, driver, drivers, client
Faunadb Python
Python driver for FaunaDB
Stars: ✭ 75 (+50%)
Mutual labels:  database, driver, drivers, client
Faunadb Js
Javascript driver for FaunaDB
Stars: ✭ 498 (+896%)
Mutual labels:  database, driver, drivers, client
Biota
A simple database framework for Fauna
Stars: ✭ 54 (+8%)
Mutual labels:  database, driver, client
Cdrs
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async
Stars: ✭ 314 (+528%)
Mutual labels:  database, driver, client
Csharp Driver
DataStax C# Driver for Apache Cassandra
Stars: ✭ 477 (+854%)
Mutual labels:  database, driver, client
Nodejs Driver
DataStax Node.js Driver for Apache Cassandra
Stars: ✭ 1,074 (+2048%)
Mutual labels:  database, driver, client
Postgres
Postgres.js - The Fastest full featured PostgreSQL client for Node.js
Stars: ✭ 2,193 (+4286%)
Mutual labels:  database, driver, client
Gocql
Package gocql implements a fast and robust Cassandra client for the Go programming language.
Stars: ✭ 2,182 (+4264%)
Mutual labels:  database, driver, client
Dokany
User mode file system library for windows with FUSE Wrapper
Stars: ✭ 4,055 (+8010%)
Mutual labels:  driver, drivers
Sqlhooks
Attach hooks to any database/sql driver
Stars: ✭ 397 (+694%)
Mutual labels:  database, driver
Rust Mysql Simple
Mysql client library implemented in rust.
Stars: ✭ 415 (+730%)
Mutual labels:  database, driver
Rdbc
Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Stars: ✭ 328 (+556%)
Mutual labels:  database, driver
Hasql
Performant PostgreSQL driver with a flexible mapping API
Stars: ✭ 415 (+730%)
Mutual labels:  database, driver
Vertica Python
Official native Python client for the Vertica Analytics Database.
Stars: ✭ 301 (+502%)
Mutual labels:  database, driver
Ruby Pg
A PostgreSQL client library for Ruby
Stars: ✭ 446 (+792%)
Mutual labels:  database, client
Study
A simple, progressive, client/server AB testing library 📚
Stars: ✭ 293 (+486%)
Mutual labels:  drivers, client
Qmgo
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.
Stars: ✭ 444 (+788%)
Mutual labels:  database, driver
Couchdb Net
EF Core-like CouchDB experience for .NET!
Stars: ✭ 50 (+0%)
Mutual labels:  database, driver
Clickhouse Driver
ClickHouse Python Driver with native interface support
Stars: ✭ 562 (+1024%)
Mutual labels:  database, driver

FaunaDB JVM Drivers

Maven Central License

This repository contains the FaunaDB drivers for the JVM languages. Currently, Java and Scala clients are implemented.

Features

Documentation

Javadocs and Scaladocs are hosted on GitHub:

Details Documentation for each language:

Dependencies

Shared

Java

  • Java 11

Scala

  • Scala 2.11.x
  • Scala 2.12.x

Using the Driver

Java

Installation

Download from the Maven central repository:

faunadb-java/pom.xml:
<dependencies>
  ...
  <dependency>
    <groupId>com.faunadb</groupId>
    <artifactId>faunadb-java</artifactId>
    <version>4.0.1</version>
    <scope>compile</scope>
  </dependency>
  ...
</dependencies>
Basic Java Usage
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();
    }
}
Document Streaming

Fauna supports document streaming, where changes to a streamed document are pushed to all clients subscribing to that document.

The streaming API is built using the java.util.concurrent.Flow which enable users to establish flow-controlled components in which Publishers produce items consumed by one or more Subscribers, each managed by a Subscription.

The following example assumes that you have already created a FaunaClient.

In the example below, we are capturing the 4 first messages by manually binding a Subscriber.

// docRef is a reference to the document for which we want to stream updates.
// You can acquire a document reference with a query like the following, but it
// needs to work with the documents that you have.
// Value docRef = Ref(Collection("scoreboards"), "123")

Flow.Publisher<Value> valuePublisher = adminClient.stream(createdDoc).get();
CompletableFuture<List<Value>> capturedEvents = new CompletableFuture<>();

Flow.Subscriber<Value> valueSubscriber = new Flow.Subscriber<>() {
  Flow.Subscription subscription = null;
  ArrayList<Value> captured = new ArrayList<>();
  @Override
  public void onSubscribe(Flow.Subscription s) {
    subscription = s;
    subscription.request(1);
  }

  @Override
  public void onNext(Value v) {
    captured.add(v);
    if (captured.size() == 4) {
      capturedEvents.complete(captured);
      subscription.cancel();
    } else {
      subscription.request(1);
    }
  }

  @Override
  public void onError(Throwable throwable) {
     capturedEvents.completeExceptionally(throwable);
  }

  @Override
  public void onComplete() {
    capturedEvents.completeExceptionally(new IllegalStateException("not expecting the stream to complete"));
  }
};

// subscribe to publisher
valuePublisher.subscribe(valueSubscriber);

// blocking
List<Value> events = capturedEvents.get();

Detailed Java Documentation can be found here

Scala

Installation

faunadb-scala/sbt
libraryDependencies += ("com.faunadb" %% "faunadb-scala" % "4.0.1")
Basic Usage
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)
}
Document Streaming

Fauna supports document streaming, where changes to a streamed document are pushed to all clients subscribing to that document.

The following sections provide examples for managing streams with Flow or Monix, and assume that you have already created a FaunaClient.

Flow subscriber

It is possible to use the java.util.concurrent.Flow API directly by binding a Subscriber manually.

In the example below, we are capturing the 4 first messages:

import faunadb._
import faunadb.query._

// docRef is a reference to the document for which we want to stream updates.
// You can acquire a document reference with a query like the following, but it
// needs to work with the documents that you have.
// val docRef = Ref(Collection("scoreboards"), "123")

client.stream(docRef).flatMap { publisher =>
  // Promise to hold the final state
  val capturedEventsP = Promise[List[Value]]

  // Our manual Subscriber
  val valueSubscriber = new Flow.Subscriber[Value] {
    var subscription: Flow.Subscription = null
    val captured = new ConcurrentLinkedQueue[Value]

    override def onSubscribe(s: Flow.Subscription): Unit = {
      subscription = s
      subscription.request(1)
    }

    override def onNext(v: Value): Unit = {
      captured.add(v)
      if (captured.size() == 4) {
        capturedEventsP.success(captured.iterator().asScala.toList)
        subscription.cancel()
      } else {
        subscription.request(1)
      }
    }

    override def onError(t: Throwable): Unit =
      capturedEventsP.failure(t)

    override def onComplete(): Unit =
      capturedEventsP.failure(new IllegalStateException("not expecting the stream to complete"))
  }
  // subscribe to publisher
  publisher.subscribe(valueSubscriber)
  // wait for Future completion
  capturedEventsP.future
}
Monix

The reactive-streams standard offers a strong interoperability in the streaming ecosystem.

We can replicate the previous example using the Monix streaming library.

import faunadb._
import faunadb.query._
import monix.execution.Scheduler
import monix.reactive.Observable
import org.reactivestreams.{FlowAdapters, Publisher}

// docRef is a reference to the document for which we want to stream updates.
// You can acquire a document reference with a query like the following, but it
// needs to work with the documents that you have.
// val docRef = Ref(Collection("scoreboards"), "123")

client.stream(docRef).flatMap { publisher =>
  val reactiveStreamsPublisher: Publisher[Value] = FlowAdapters.toPublisher(publisherValue)
  Observable.fromReactivePublisher(reactiveStreamsPublisher)
    .take(4) // 4 events
    .toListL
    .runToFuture(Scheduler.Implicits.global)
}

Building

The faunadb-jvm project is built using sbt:

To build and run tests against cloud, set the env variable FAUNA_ROOT_KEY to your admin key secret and run sbt test from the project directory.

Alternatively, tests can be run via a Docker container with FAUNA_ROOT_KEY="your-cloud-secret" make docker-test (an alternate Debian-based JDK image can be provided via RUNTIME_IMAGE).

To run tests against an enterprise cluster or developer instance, you will also need to set FAUNA_SCHEME (http or https), FAUNA_DOMAIN and FAUNA_PORT.

License

All projects in this repository are licensed under the Mozilla Public License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].