Exemple #1
0
 def __init__(self, dataset_id=None, namespace=None, connection=None):
     dataset_id = _determine_default_dataset_id(dataset_id)
     if dataset_id is None:
         raise EnvironmentError('Dataset ID could not be inferred.')
     self.dataset_id = dataset_id
     if connection is None:
         connection = Connection.from_environment()
     self.connection = connection
     self._batch_stack = _LocalStack()
     self.namespace = namespace
Exemple #2
0
 def __init__(self, dataset_id=None, namespace=None, connection=None):
     dataset_id = _determine_default_dataset_id(dataset_id)
     if dataset_id is None:
         raise EnvironmentError('Dataset ID could not be inferred.')
     self.dataset_id = dataset_id
     if connection is None:
         connection = Connection.from_environment()
     self.connection = connection
     self._batch_stack = _LocalStack()
     self.namespace = namespace
def get_connection():
    """Shortcut method to establish a connection to the Cloud Datastore.

    Use this if you are going to access several datasets
    with the same set of credentials (unlikely):

    >>> from gcloud import datastore

    >>> connection = datastore.get_connection()
    >>> key1 = datastore.Key('Kind', 1234, dataset_id='dataset1')
    >>> key2 = datastore.Key('Kind', 1234, dataset_id='dataset2')
    >>> entity1 = datastore.get(key1, connection=connection)
    >>> entity2 = datastore.get(key2, connection=connection)

    :rtype: :class:`gcloud.datastore.connection.Connection`
    :returns: A connection defined with the proper credentials.
    """
    return Connection.from_environment()