diff --git a/README.rst b/README.rst index c7a8eafa39a3..31a6fcf77a23 100644 --- a/README.rst +++ b/README.rst @@ -64,7 +64,6 @@ with the Cloud Datastore using this Client Library. .. code:: python from gcloud import datastore - datastore.set_defaults() # Create, populate and persist an entity entity = datastore.Entity(key=datastore.Key('EntityKind')) entity.update({ diff --git a/docs/_components/datastore-getting-started.rst b/docs/_components/datastore-getting-started.rst index 457f9ce79b74..494ace837ee5 100644 --- a/docs/_components/datastore-getting-started.rst +++ b/docs/_components/datastore-getting-started.rst @@ -38,7 +38,6 @@ Add some data to your dataset Open a Python console and... >>> from gcloud import datastore - >>> datastore.set_defaults() >>> list(datastore.Query(kind='Person').fetch()) [] >>> entity = datastore.Entity(key=datastore.Key('Person')) diff --git a/docs/index.rst b/docs/index.rst index e6d7008f8998..7a8c3f8037cb 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,6 @@ Cloud Datastore .. code-block:: python from gcloud import datastore - datastore.set_defaults() entity = datastore.Entity(key=datastore.Key('Person')) entity['name'] = 'Your name' diff --git a/gcloud/datastore/__init__.py b/gcloud/datastore/__init__.py index 98ce39854619..1030f0b61cb6 100644 --- a/gcloud/datastore/__init__.py +++ b/gcloud/datastore/__init__.py @@ -18,8 +18,6 @@ >>> from gcloud import datastore ->>> datastore.set_defaults() - >>> key = datastore.Key('EntityKind', 1234) >>> entity = datastore.Entity(key) >>> query = datastore.Query(kind='EntityKind') diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index 57724fec0c54..1fa4e42fcdac 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -147,7 +147,6 @@ def lookup(self, dataset_id, key_pbs, under the hood in :func:`gcloud.datastore.get`: >>> from gcloud import datastore - >>> datastore.set_defaults() >>> key = datastore.Key('MyKind', 1234, dataset_id='dataset-id') >>> datastore.get([key]) [] @@ -210,8 +209,6 @@ def run_query(self, dataset_id, query_pb, namespace=None, >>> from gcloud import datastore - >>> datastore.set_defaults() - >>> query = datastore.Query(kind='MyKind') >>> query.add_filter('property', '=', 'val') diff --git a/gcloud/datastore/demo/__init__.py b/gcloud/datastore/demo/__init__.py index bf0b92d9c998..d6624af64eb5 100644 --- a/gcloud/datastore/demo/__init__.py +++ b/gcloud/datastore/demo/__init__.py @@ -23,4 +23,4 @@ def initialize(): - datastore.set_defaults(dataset_id=DATASET_ID) + datastore.set_default_dataset_id(DATASET_ID) diff --git a/gcloud/datastore/transaction.py b/gcloud/datastore/transaction.py index 4063fd3c7144..7e0d461dce7b 100644 --- a/gcloud/datastore/transaction.py +++ b/gcloud/datastore/transaction.py @@ -28,24 +28,21 @@ class Transaction(Batch): mutation, and execute those within a transaction:: >>> from gcloud import datastore - >>> from gcloud.datastore.transaction import Transaction - >>> datastore.set_defaults() - - >>> with Transaction(): + >>> with datastore.Transaction(): ... datastore.put([entity1, entity2]) Because it derives from :class:`Batch`, :class`Transaction` also provides :meth:`put` and :meth:`delete` methods:: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... xact.put(entity1) ... xact.delete(entity2.key) By default, the transaction is rolled back if the transaction block exits with an error:: - >>> with Transaction(): + >>> with datastore.Transaction(): ... do_some_work() ... raise SomeException() # rolls back @@ -56,8 +53,8 @@ class Transaction(Batch): entities will not be available at save time! That means, if you try:: - >>> with Transaction(): - ... entity = Entity(key=Key('Thing')) + >>> with datastore.Transaction(): + ... entity = datastore.Entity(key=Key('Thing')) ... datastore.put([entity]) ``entity`` won't have a complete Key until the transaction is @@ -66,8 +63,8 @@ class Transaction(Batch): Once you exit the transaction (or call ``commit()``), the automatically generated ID will be assigned to the entity:: - >>> with Transaction(): - ... entity = Entity(key=Key('Thing')) + >>> with datastore.Transaction(): + ... entity = datastore.Entity(key=Key('Thing')) ... datastore.put([entity]) ... assert entity.key.is_partial # There is no ID on this key. ... @@ -76,7 +73,7 @@ class Transaction(Batch): After completion, you can determine if a commit succeeded or failed. For example, trying to delete a key that doesn't exist:: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... xact.delete(key) ... >>> xact.succeeded @@ -84,7 +81,7 @@ class Transaction(Batch): or successfully storing two entities: - >>> with Transaction() as xact: + >>> with datastore.Transaction() as xact: ... datastore.put([entity1, entity2]) ... >>> xact.succeeded @@ -93,10 +90,10 @@ class Transaction(Batch): If you don't want to use the context manager you can initialize a transaction manually:: - >>> transaction = Transaction() + >>> transaction = datastore.Transaction() >>> transaction.begin() - >>> entity = Entity(key=Key('Thing')) + >>> entity = datastore.Entity(key=Key('Thing')) >>> transaction.put(entity) >>> if error: