FoundationDB client for Scala

I am really impressed with FoundationDB, so lately I’ve started working on a client for Scala. The goal is to create API that is type-safe and idiomatic for Scala: https://github.com/pwliwanow/foundationdb4s

I’ve implemented ClassScheduling example from the docs, to give better understanding how using the library looks like (link to the Scala implementation: https://github.com/pwliwanow/foundationdb4s/blob/master/example/src/main/scala/com/github/pwliwanow/foundationdb4s/example/ClassScheduling.scala).

Of course not everything is yet implemented (but more functionalities are coming!), and if you have any suggestions please let me know or create an issue on GitHub.

7 Likes

In the newest release (0.10.1) there are two features added, which I think are interesting enough to be shared here:

  1. Compile-time derivation of tuple encoders and tuple decoders for custom case classes. For example:
import com.apple.foundationdb.tuple.Tuple
import com.github.pwliwanow.foundationdb4s.schema.{TupleDecoder, TupleEncoder}

case class Foo(a: Long, b: String, c: Boolean)

implicit val fooDecoder: TupleDecoder[Foo] = TupleDecoder.derive[Foo]
implicit val fooEncoder: TupleEncoder[Foo] = TupleEncoder.derive[Foo]

val foo = Foo(1L, "b", false)
val tuple: Tuple = fooEnoder.encode(foo)
val decodedFoo: Foo = fooDecoder.decode(tuple)

In particular:

  • Compilation will fail if given class contains field for which there doesn’t exist implicit TupleDecoder/TupleEncoder.
  • Derived codecs support schema evolution, e.g. if value was encoded using TupleEncoder[(String, Int)], it is possible to read the key with TupleDecoder[(String, Int, Option[A])] or with TupleDecoder[(String, Int, List[A])] (where A is any type for which TupleDecoder[A] exist).
  • Derivation supports nested structures.
  • New codecs may be defined by leveraging already existing ones:
implicit val localDateEnc = implicitly[TupleEncoder[Long]].contramap[LocalDate](_.toEpochDay)
implicit val localDateDec = implicitly[TupleDecoder[Long]].map(LocalDate.ofEpochDay)
  1. Support for application level schema for namespaces - it enables operations like range, getRange, clear etc. to be type-safe.

More details in README section about application level schema. Example “class scheduling” was rewritten to take advantage of those type-safe operations and to show how it can be used in an application.

All questions and suggestions are very much welcome!

2 Likes

. I have been using your Scala client for a while now.The new schema module looks great

1 Like