The Fauna service will be ending on May 30, 2025.

For more information on the service wind down, see our announcement and the Fauna Service End-of-Life FAQ.

Scala

This section is intended to help Scala developers get started using the Fauna Scala driver for application development.

Current version and repository location

Current stable version

4.5.0

Repository

Dependencies

  • Scala 2.11.x

  • Scala 2.12.x

  • Jackson for JSON parsing.

Installation

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

Example application

The following example code runs a bare-bones Scala application which creates a new document in a

collection called People.

Prerequisites

  • A Fauna account.

  • A supported version of Scala and the Fauna Scala driver.

  • sbt, version 1.4 or higher.

Procedure

  1. Navigate to the Fauna v4 Dashboard

    Log in to your Fauna account at v10 Fauna Dashboard if you’re not already logged in.

  2. Create a new database

    Create a new database and select your Region Group.

  3. Access the v4 Dashboard

    Access the Fauna v4 Dashboard by clicking the v4 Dashboard tab for the database.

  4. Create a new collection

    Under Collections, click NEW COLLECTION. Name your new collection People and save it.

  5. Create an access key

    Click SECURITY in the left-side navigation menu. Create a new key for your database. Be sure to save the key’s secret in a safe place, as it is only displayed once.

  6. Create a local environment variable with your access key’s secret

    On MacOS and Linux systems, enter the following in a terminal window:

    export FAUNADB_SECRET=<your-secret>

    For Windows systems, enter the following in a terminal window:

    set FAUNADB_SECRET=<your secret>

    For either example, replace <your secret> with the secret for the access key that you created.

  7. Create a project folder using the standard directory layout

    In a terminal window, in an empty folder, run the following command:

    sbt new scala/hello-world.g8

    When prompted, name the project example.

    Then enter the folder:

    cd example
  8. Edit the build.sbt file

    With your preferred editor, replace the contents of the build.sbt file with the following:

    ThisBuild / scalaVersion := "2.12.15"
    ThisBuild / version := "0.1.0"
    ThisBuild / organization := "com.example"
    ThisBuild / organizationName := "example"
    ThisBuild / showSuccess := false
    
    lazy val root = (project in file("."))
      .settings(
        name := "example",
        libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.7.28",
        libraryDependencies += "com.faunadb" %% "faunadb-scala" % "4.5.0"
      )
  9. Create a local application file

    With your preferred editor, replace the contents of the src/main/scala/Main.scala file with the following code:

  10. Compile and run the application

    sbt run

    You should see results similar to this:

    If you get an error, check to make sure that the secret for your access key is correct.

\