Skip to content

Transactions

Compare
Choose a tag to compare
@guregu guregu released this 08 Jan 17:25
· 200 commits to master since this release
d8bb6a0

This release adds support for DynamoDB transactions! For a quick and dirty intro to them, see tx_test.go.
You create transactions by composing pre-existing parts of the library such as Update and Delete.

For example, imagine a game where you can give money to other players. The following transaction models Alice giving 100 gold to Bob and adding a log to a separate table, but only if Alice has enough gold.

tx := db.WriteTx()
users := db.Table("Users")
logs := db.Table("TradeLogs")
amount := 100
tx.Update(users.Update("UserID", "Alice").Add("Gold", -amount).If("Gold >= ?", amount))
tx.Update(users.Update("UserID", "Bob").Add("Gold", amount))
tx.Put(logs.Put(TradeLog{From: "Alice", To: "Bob", Amount: amount, Time: time.Now()}))
err := tx.Run()

If any part of the transaction fails, it will be rolled back and an appropriate error will be returned.

The official AWS Go SDK is still missing some transactions features, and we'll add support for them as they trickle in.
This release also adds support for Go modules.