def _purge_report_items(report): # Delete any existing items belonging to report count = 0 for item in _fetch_report_items(report): datastore.delete([item.key]) count += 1 return count
def remove_kind(kind): results = [] query, curr_results, cursor = fetch_keys(kind) results.extend(curr_results) while curr_results: query, curr_results, cursor = fetch_keys(kind, query=query, cursor=cursor) results.extend(curr_results) if not results: return delete_outside_transaction = False with datastore.Transaction(): # Now that we have all results, we seek to delete. print('Deleting keys:') print(results) ancestors = get_ancestors(results) if len(ancestors) > TRANSACTION_MAX_GROUPS: delete_outside_transaction = True else: datastore.delete([result.key for result in results]) if delete_outside_transaction: datastore.delete([result.key for result in results])
def delete_report(employee_id, report_id, force): with Transaction(): report = _get_report(employee_id, report_id, False) if report is None: raise NoSuchReport() if report['status'] != 'pending' and not force: raise BadReportStatus(report['status']) count = _purge_report_items(report) datastore.delete([report.key]) return count
# Let's import the package containing our helper classes: # Let's create a new entity of type "Thing" and name it 'Toy': key = datastore.Key('Thing') toy = datastore.Entity(key) toy.update({'name': 'Toy'}) # Now let's save it to our datastore: datastore.put(toy) # If we look it up by its key, we should find it... print(datastore.get(toy.key)) # And we should be able to delete it... datastore.delete(toy.key) # Since we deleted it, if we do another lookup it shouldn't be there again: print(datastore.get(toy.key)) # Now let's try a more advanced query. # First, let's create some entities. SAMPLE_DATA = [ (1234, 'Computer', 10), (2345, 'Computer', 8), (3456, 'Laptop', 10), (4567, 'Printer', 11), (5678, 'Printer', 12), (6789, 'Computer', 13)] sample_keys = [] for id, name, age in SAMPLE_DATA:
def tearDown(self): with datastore.Transaction(): keys = [entity.key for entity in self.case_entities_to_delete] datastore.delete(keys)
# Let's import the package containing our helper classes: # Let's create a new entity of type "Thing" and name it 'Toy': key = datastore.Key('Thing') toy = datastore.Entity(key) toy.update({'name': 'Toy'}) # Now let's save it to our datastore: datastore.put([toy]) # If we look it up by its key, we should find it... print(datastore.get([toy.key])) # And we should be able to delete it... datastore.delete([toy.key]) # Since we deleted it, if we do another lookup it shouldn't be there again: print(datastore.get([toy.key])) # Now let's try a more advanced query. # First, let's create some entities. SAMPLE_DATA = [(1234, 'Computer', 10), (2345, 'Computer', 8), (3456, 'Laptop', 10), (4567, 'Printer', 11), (5678, 'Printer', 12), (6789, 'Computer', 13)] sample_keys = [] for id, name, age in SAMPLE_DATA: key = datastore.Key('Thing', id) sample_keys.append(key) entity = datastore.Entity(key) entity['name'] = name
def remove(cls, id): from gcloud import datastore obj = cls(id=id) datastore.delete([obj.key])
# Let's import the package containing our helper classes: # Let's create a new entity of type "Thing" and name it 'Toy': key = datastore.Key('Thing') toy = datastore.Entity(key) toy.update({'name': 'Toy'}) # Now let's save it to our datastore: datastore.put([toy]) # If we look it up by its key, we should find it... print(datastore.get([toy.key])) # And we should be able to delete it... datastore.delete([toy.key]) # Since we deleted it, if we do another lookup it shouldn't be there again: print(datastore.get([toy.key])) # Now let's try a more advanced query. # First, let's create some entities. SAMPLE_DATA = [ (1234, 'Computer', 10), (2345, 'Computer', 8), (3456, 'Laptop', 10), (4567, 'Printer', 11), (5678, 'Printer', 12), (6789, 'Computer', 13)] sample_keys = [] for id, name, age in SAMPLE_DATA:
# Let's import the package containing our helper classes: # Let's create a new entity of type "Thing" and name it 'Toy': key = datastore.Key('Thing') toy = datastore.Entity(key) toy.update({'name': 'Toy'}) # Now let's save it to our datastore: datastore.put(toy) # If we look it up by its key, we should find it... print(datastore.get(toy.key)) # And we should be able to delete it... datastore.delete(toy.key) # Since we deleted it, if we do another lookup it shouldn't be there again: print(datastore.get(toy.key)) # Now let's try a more advanced query. # First, let's create some entities. SAMPLE_DATA = [(1234, 'Computer', 10), (2345, 'Computer', 8), (3456, 'Laptop', 10), (4567, 'Printer', 11), (5678, 'Printer', 12), (6789, 'Computer', 13)] sample_keys = [] for id, name, age in SAMPLE_DATA: key = datastore.Key('Thing', id) sample_keys.append(key) entity = datastore.Entity(key) entity['name'] = name