Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
#514: add datastore.put API, remove `Entity.save'#548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ec54e98b2d33ff61cb02d84d47f96873f1de27070e8a6127ed46ed28File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -28,7 +28,7 @@ | ||
| toy.update({'name': 'Toy'}) | ||
| # Now let's save it to our datastore: | ||
| toy.save() | ||
| datastore.put([toy]) | ||
| # If we look it up by its key, we should find it... | ||
| print(datastore.get([toy.key])) | ||
| @@ -55,7 +55,7 @@ | ||
| entity = datastore.Entity(key) | ||
| entity['name'] = name | ||
| entity['age'] = age | ||
| entity.save() | ||
| datastore.put([entity]) | ||
| # We'll start by look at all Thing entities: | ||
| query = datastore.Query(kind='Thing') | ||
| @@ -76,41 +76,41 @@ | ||
| # You can also work inside a transaction. | ||
| # (Check the official docs for explanations of what's happening here.) | ||
| with datastore.Transaction(): | ||
| with datastore.Transaction() as xact: | ||
| print('Creating and saving an entity...') | ||
| key = datastore.Key('Thing', 'foo') | ||
| thing = datastore.Entity(key) | ||
| thing['age'] = 10 | ||
| thing.save() | ||
| xact.put(thing) | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| print('Creating and saving another entity...') | ||
| key2 = datastore.Key('Thing', 'bar') | ||
| thing2 = datastore.Entity(key2) | ||
| thing2['age'] = 15 | ||
| thing2.save() | ||
| xact.put(thing2) | ||
| print('Committing the transaction...') | ||
| # Now that the transaction is commited, let's delete the entities. | ||
| datastore.delete([key, key2]) | ||
| # To rollback a transaction, just call .rollback() | ||
| with datastore.Transaction() as t: | ||
| with datastore.Transaction() as xact: | ||
| key = datastore.Key('Thing', 'another') | ||
| thing = datastore.Entity(key) | ||
| thing.save() | ||
| t.rollback() | ||
| xact.put(thing) | ||
| xact.rollback() | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| # Let's check if the entity was actually created: | ||
| created = datastore.get([key]) | ||
| print('yes' if created else 'no') | ||
| # Remember, a key won't be complete until the transaction is commited. | ||
| # That is, while inside the transaction block, thing.key will be incomplete. | ||
| with datastore.Transaction(): | ||
| with datastore.Transaction() as xact: | ||
| key = datastore.Key('Thing') # partial | ||
| thing = datastore.Entity(key) | ||
| thing.save() | ||
| xact.put(thing) | ||
| print(thing.key) # This will still be partial | ||
| print(thing.key) # This will be complete | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.