Overview

Firebase4s aims to provide a Scala-friendly alternative to the Firebase Java SDK. By providing more idiomatic API interfaces and automatically handling Scala-to-Java data conversions, Firebase4s eliminates much of the boilerplate required to use the Java SDK. Firebase4s currently provides the same Realtime Database and Authentication features as the Java SDK and aims to provide all of the same functionality over time.

Getting Started

To use firebase4s in your project, add the following to your build.sbt:

libraryDependencies +="com.github.firebase4s"%%"firebase4s"%"0.0.4"

Initialize

Initialize the App with your Firebase service account credentials and database url, which may be obtained from the Firebase console.

Simple Types: String, Boolean, Int, Long, Double

Iterables containing Simple Types: List[String] , Vector[Long], etc.

Options of any of the above: Option[Int], Option[List[String]], etc.

Classes

Currently, only JavaBean classes are supported. However, Firebase4s offers a toMap helper method which makes working with non-nested case classes easier. Future versions of Firebase4s will fully support the use of case classes through the use of Scala Macro Annotations. and/or Shapeless

/** * The Helpers module provides a `toMap` method which * we can invoke on our case class to convert it to a * Map[String, Any] that can be set as a value in the * in the database. When retrieving the value as this * ref location, we will get back a Map[String, Any] * representation of our case class instance.*/importcom.firebase4s.database.Helpers._caseclassUser(name: String, age: Int)
valuser=User("tim", 44)
valuserRef= db.ref("user")
userRef.set(user.toMap)
userRef.get().foreach(snapshot => {
println(snapshot.getValue) // Map(name -> tim, age -> 44)
})