Last active
September 30, 2019 23:12
-
-
Save evbruno/1558ab65391f3786864b540e226775b9 to your computer and use it in GitHub Desktop.
FQL to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
// build.sbt | |
scalaVersion := "2.11.8" | |
libraryDependencies ++= Seq("com.faunadb" %% "faunadb-scala" % "2.8.1") | |
*/ | |
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} | |
import faunadb.{query => q} | |
object FQLToJson extends App { | |
val query = q.Insert( | |
q.Let { | |
val ticker = q.Match(q.Index("stock_price_by_ticker"), "FAUNA") | |
q.If( | |
q.Exists(ticker), | |
q.Select("ref", q.Get(ticker)), | |
q.Ref(q.Collection("stock_price"), q.NewId()) | |
) | |
}, | |
q.Time("2019-01-01T00:00:00Z"), | |
"update", | |
q.Obj( | |
"data" -> q.Obj( | |
"ticker" -> "FAUNA", | |
"price" -> 1234.56 | |
) | |
) | |
) | |
val json = new ObjectMapper().findAndRegisterModules | |
json.enable(SerializationFeature.INDENT_OUTPUT) // pretty print | |
println(json.writeValueAsString(query)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment