Is this specifically for distributed SQL only? I think there are some scalable SQL systems that don't support sessions either.
Is this specifically for distributed SQL only? I think there are some scalable SQL systems that don't support sessions either.
Multi-query transactions can be useful, but the FaunaDB query language is functional, rather than declarative like SQL, so composing queries that can do everything you want is usually easier than SQL.
Would you create a single operation that reads one record, checks that it's enough, then adds the amount to another record?
Or maybe you'd first read both accounts, then issue a conditional write operation that makes sure the data hasn't changed before doing the write?
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"
)
}(BTW, would be nice if I could read your API docs without signing up for an account.)
The docs will eventually be available without an account.