Thursday, March 7, 2013

Start FoundationDB with Scala (Update to Version 1.0.2)


So, FoundationDB has released version 1.0.2 already.  If you haven't heard about FoundationDB, it is basically a key-value storage with strong transaction support and rich built-in data model.



FoundationDB deals with bytes directly, this is like HBase.

Java SDK:

libraryDependencies += "com.foundationdb" % "fdb-java" % "1.0.0"

Hello World example in Scala
import com.foundationdb._
import com.foundationdb.tuple.{Tuple => FTuple}
import com.foundationdb.async.{Function => FDBFunction}
object Hi extends App{
val fdb = FDB.selectAPIVersion(100);
val db = fdb.open()
db.run(new FDBFunction[Transaction, Unit](){
override def apply(tr: Transaction) {
tr.set(FTuple.from("hello").pack, FTuple.from("world").pack)
}
})
val hello = db.run(new FDBFunction[Transaction, String](){
override def apply(tr: Transaction): String = {
val result = tr.get(FTuple.from("hello").pack()).get
FTuple.fromBytes(result).getString(0)
}
})
println("Hello "+ hello)
}




https://github.com/yuanw/foundation-DB-tutorial

No comments:

Post a Comment