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_multi([result.key for result in results])

    if delete_outside_transaction:
        datastore.delete_multi([result.key for result in results])
Exemple #2
0
 def tearDown(self):
     with datastore.Transaction():
         keys = [entity.key for entity in self.case_entities_to_delete]
         datastore.delete_multi(keys)
Exemple #3
0
query = datastore.Query(kind='Thing')

# Let's look at the first two.
print(list(query.fetch(limit=2)))

# Now let's check for Thing entities named 'Computer'
query.add_filter('name', '=', 'Computer')
print(list(query.fetch()))

# If you want to filter by multiple attributes,
# you can call .add_filter multiple times on the query.
query.add_filter('age', '=', 10)
print(list(query.fetch()))

# Now delete them.
datastore.delete_multi(sample_keys)

# You can also work inside a transaction.
# (Check the official docs for explanations of what's happening here.)
with datastore.Transaction() as xact:
    print('Creating and saving an entity...')
    key = datastore.Key('Thing', 'foo')
    thing = datastore.Entity(key)
    thing['age'] = 10
    xact.put(thing)

    print('Creating and saving another entity...')
    key2 = datastore.Key('Thing', 'bar')
    thing2 = datastore.Entity(key2)
    thing2['age'] = 15
    xact.put(thing2)
Exemple #4
0
query = datastore.Query(kind='Thing')

# Let's look at the first two.
print(list(query.fetch(limit=2)))

# Now let's check for Thing entities named 'Computer'
query.add_filter('name', '=', 'Computer')
print(list(query.fetch()))

# If you want to filter by multiple attributes,
# you can call .add_filter multiple times on the query.
query.add_filter('age', '=', 10)
print(list(query.fetch()))

# Now delete them.
datastore.delete_multi(sample_keys)

# You can also work inside a transaction.
# (Check the official docs for explanations of what's happening here.)
with datastore.Transaction() as xact:
    print('Creating and saving an entity...')
    key = datastore.Key('Thing', 'foo')
    thing = datastore.Entity(key)
    thing['age'] = 10
    xact.put(thing)

    print('Creating and saving another entity...')
    key2 = datastore.Key('Thing', 'bar')
    thing2 = datastore.Entity(key2)
    thing2['age'] = 15
    xact.put(thing2)