Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Google App Engine

You're reading from   Mastering Google App Engine Build robust and highly scalable web applications with Google App Engine

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781784396671
Length 368 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Transactions

There are cases where you'd want a number of operations to succeed or fail altogether and nothing in between. This is called a transaction, and App Engine's datastore offers support for transactions. In App Engine, you do this by encapsulating all the steps that you want to fail or succeed together in a function and decorate it with the ndb.transactional decorator.

Let's suppose that it so happens that we add a new property called city to indicate the city that the car is in. Sometimes, two cars are exchanged between two dealers in two difference cities. In that case, we need to update the cities of these two listings and basically swap them. There are multiple datastore operations involved here, given that we have keys for both the listings. First, we read both the listings from datastore, then modify the cities, and finally, we write them back. All of these operations shall either fail altogether, or succeed altogether. This is how we will do this by wrapping...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime