예제 #1
0
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
예제 #2
0
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])
예제 #3
0
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])
예제 #4
0
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
예제 #5
0
# 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:
예제 #6
0
 def tearDown(self):
     with datastore.Transaction():
         keys = [entity.key for entity in self.case_entities_to_delete]
         datastore.delete(keys)
예제 #7
0
# 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
예제 #8
0
 def remove(cls, id):
     from gcloud import datastore
     obj = cls(id=id)
     datastore.delete([obj.key])
예제 #9
0
# 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:
예제 #10
0
 def tearDown(self):
     with datastore.Transaction():
         keys = [entity.key for entity in self.case_entities_to_delete]
         datastore.delete(keys)
예제 #11
0
# 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