4 ms·
FaunaDB's query language makes it straightforward to do it the first way. All queries are serializable, so any preconditions checked would gate transaction comm
by freels 10y ago
FaunaDB's query language makes it straightforward to do it the first way. All queries are serializable, so any preconditions checked would gate transaction commit as you would expect, and read-modify-write style transactions work.
edit: here's an example in our Scala DSL:
Let {
val amount = 50
val balanceA = Select("data" / "balance", Get(Ref("accountA"))
val balanceB = Select("data" / "balance", Get(Ref("accountB"))
If(Gteq(balanceA, amount),
Do(
Update(Ref("accountA"), Obj("data" -> Obj("balance" -> Subtract(balanceA, amount)))),
Update(Ref("accountB"), Obj("data" -> Obj("balance" -> Add(balanceB, amount)))),
"Transfer Success"
),
"Insufficient Funds"
)
}
- cakoose 10y agoIs the wire format roughly isomorphic to the structure above? Or does the Scala library convert this code-like structure into something simpler/flatter? (BTW, would be nice if I could read your API docs without signing up for an account.)
- evanweaver 10y agoIt is isomorphic; right now it's layered onto JSON, but eventually we will support CBOR on the wire as well. Internally everything is CBOR with LZ4 block compression. The docs will eventually be available without an account.