def delete(keys, connection=None, dataset_id=None): """Delete the keys in the Cloud Datastore. :type keys: list of :class:`gcloud.datastore.key.Key` :param keys: The keys to be deleted from the datastore. :type connection: :class:`gcloud.datastore.connection.Connection` :param connection: Optional connection used to connect to datastore. If not passed, inferred from the environment. :type dataset_id: :class:`gcloud.datastore.connection.Connection` :param dataset_id: Optional. The dataset ID used to connect to datastore. If not passed, inferred from the environment. :raises: EnvironmentError if ``connection`` or ``dataset_id`` not passed, and cannot be inferred from the environment. ValueError if one or more keys has a dataset ID not matching the passed / inferred dataset ID. """ if not keys: return connection = _require_connection(connection) dataset_id = _require_dataset_id(dataset_id, keys[0]) # We allow partial keys to attempt a delete, the backend will fail. current = Batch.current() in_batch = current is not None if not in_batch: current = Batch(dataset_id=dataset_id, connection=connection) for key in keys: current.delete(key) if not in_batch: current.commit()
def delete_multi(keys, connection=None, dataset_id=None): """Delete the keys in the Cloud Datastore. :type keys: list of :class:`gcloud.datastore.key.Key` :param keys: The keys to be deleted from the datastore. :type connection: :class:`gcloud.datastore.connection.Connection` :param connection: Optional connection used to connect to datastore. If not passed, inferred from the environment. :type dataset_id: :class:`gcloud.datastore.connection.Connection` :param dataset_id: Optional. The dataset ID used to connect to datastore. If not passed, inferred from the environment. :raises: EnvironmentError if ``connection`` or ``dataset_id`` not passed, and cannot be inferred from the environment. ValueError if one or more keys has a dataset ID not matching the passed / inferred dataset ID. """ if not keys: return connection = _require_connection(connection) dataset_id = _require_dataset_id(dataset_id, keys[0]) # We allow partial keys to attempt a delete, the backend will fail. current = Batch.current() in_batch = current is not None if not in_batch: current = Batch(dataset_id=dataset_id, connection=connection) for key in keys: current.delete(key) if not in_batch: current.commit()
def put(entities, connection=None, dataset_id=None): """Save the entities in the Cloud Datastore. :type entities: list of :class:`gcloud.datastore.entity.Entity` :param entities: The entities to be saved to the datastore. :type connection: :class:`gcloud.datastore.connection.Connection` :param connection: Optional connection used to connect to datastore. If not passed, inferred from the environment. :type dataset_id: :class:`gcloud.datastore.connection.Connection` :param dataset_id: Optional. The dataset ID used to connect to datastore. If not passed, inferred from the environment. :raises: EnvironmentError if ``connection`` or ``dataset_id`` not passed, and cannot be inferred from the environment. ValueError if one or more entities has a key with a dataset ID not matching the passed / inferred dataset ID. """ if not entities: return connection = _require_connection(connection) dataset_id = _require_dataset_id(dataset_id, entities[0].key) current = Batch.current() in_batch = current is not None if not in_batch: current = Batch(dataset_id=dataset_id, connection=connection) for entity in entities: current.put(entity) if not in_batch: current.commit()
def delete(keys, connection=None): """Delete the keys in the Cloud Datastore. :type keys: list of :class:`gcloud.datastore.key.Key` :param keys: The keys to be deleted from the datastore. :type connection: :class:`gcloud.datastore.connection.Connection` :param connection: Optional connection used to connect to datastore. """ if not keys: return connection = connection or _implicit_environ.CONNECTION # We allow partial keys to attempt a delete, the backend will fail. current = Batch.current() in_batch = current is not None if not in_batch: dataset_id = _get_dataset_id_from_keys(keys) current = Batch(dataset_id=dataset_id, connection=connection) for key in keys: current.delete(key) if not in_batch: current.commit()
def put(entities, connection=None): """Save the entities in the Cloud Datastore. :type entities: list of :class:`gcloud.datastore.entity.Entity` :param entities: The entities to be saved to the datastore. :type connection: :class:`gcloud.datastore.connection.Connection` :param connection: Optional connection used to connect to datastore. """ if not entities: return connection = connection or _implicit_environ.CONNECTION current = Batch.current() in_batch = current is not None if not in_batch: keys = [entity.key for entity in entities] dataset_id = _get_dataset_id_from_keys(keys) current = Batch(dataset_id=dataset_id, connection=connection) for entity in entities: current.put(entity) if not in_batch: current.commit()