Backends¶
Datastore¶
-
class
bread.backends.cloud_datastore.CloudDatastoreBackend[source]¶ Bases:
bread.backend.BackendGoogle Cloud Datastore backend wrapper implementation.
-
CURSOR_SEP= '-*^v^*-'¶
-
FAKE_STOP_CURSOR= 'STOP'¶
-
begin()[source]¶ Create a new
BackendTransactioninstance specific to the current backend.
-
delete(**kwargs)[source]¶ Delete a set of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
-
delete_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
delete().Returns: A Future representing the backend computation.
-
fetch(**kwargs)[source]¶ Query entities.
Note that this implementation is unable to support the
nextparameter due to an issue where Cloud Datastore ALWAYS returns that there are more results after the limit set in the query, even when there are none. The gcloud-python library then conservatively changes that respose to indicate there are NEVER more results.https://github.com/GoogleCloudPlatform/gcloud-python/issues/280
-
fetch_async(of_type, query, order, limit, cursor, dataset=None, collection=None)[source]¶ Asynchronous variant of
fetch().Warning: Calling this method on queries with multiple in filters may cause a deadlock. Returns: A future representing the result tuple.
-
get(**kwargs)[source]¶ Get a list of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
Returns: A list of Entities.
-
get_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
get().Returns: A Future representing a list of Entities.
-
Memcache¶
-
class
bread.backends.memcache.MemcacheBackend(backend, pool)[source]¶ Bases:
bread.backend.BackendA higher-order backend that adds implicit caching of get{,_async} operations on top of any given Backend.
The backend caches all get or get_async calls according to its Policy. Entities’ individual caches are invalidated every time they are saved or deleted.
The backend _does not_ attempt to cache queries in any way. All calls to fetch and fetch_asnyc are pass through directly to the underlying backend.
- Parameters:
- backend (Backend) pool (pylibmc.ThreadMappedPool)
-
begin()[source]¶ Create a new
BackendTransactioninstance specific to the current backend.
-
delete(keys, dataset=None, collection=None)[source]¶ Delete a set of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
-
delete_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
delete().Returns: A Future representing the async computation.
-
get(keys, dataset=None, collection=None)[source]¶ Get a list of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
Returns: A list of Entities.
-
get_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
get().Returns: A Future representing a list of Entities.
-
policy_class¶
Reauthorize the underlying connection for this backend. The default implementation is a no-op.
-
class
bread.backends.memcache.MemcachePolicy[source]¶ Bases:
bread.backend.Policy,bread.backends.memcache.PolicyRuntime policy for the Memcache Backend.
- Parameters:
- skip_cache (bool): If this is True, the cache is skipped
- when retrieving data (i.e. in calls to get{,_async} and fetch{,_async}). Saving data will still hit the cache in order to invalidate said data.
- entity_ttl (int): The amount of seconds that entities should be
- cached for. This is an upper bound, entities may end up being cached for less time.
- Examples:
>>> backend.set_default_policy(MemcachePolicy.build(entity_ttl=60)) >>> backend.policy MemcachePolicy(skip_cache=False, entity_ttl=60) >>> with backend.local_policy(skip_cache=True): ... AModel.get("some-id")
Stub¶
-
class
bread.backends.stub.Entry(uuid, data)¶ Bases:
tuple-
data¶ Alias for field number 1
-
uuid¶ Alias for field number 0
-
-
class
bread.backends.stub.StubBackend[source]¶ Bases:
bread.backend.BackendAn in-memory backend.
The primary use-case for this backend is unit testing.
-
OP_TABLE= {'!=': <function ne>, '<': <function lt>, '<=': <function le>, '=': <function eq>, '>': <function gt>, '>=': <function ge>, 'in': <function contains>}¶
-
ORDER_OP_TABLE= {'asc': <function <lambda>>, 'desc': <function <lambda>>}¶
-
begin()[source]¶ Create a new
BackendTransactioninstance specific to the current backend.
-
delete(keys, dataset=None, collection=None)[source]¶ Delete a set of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
-
delete_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
delete().Returns: A Future representing the async computation.
-
fetch(of_type, query, order, limit, cursor, dataset=None, collection=None)[source]¶ Query entities.
Backends must support queries where the query is a list of tuples, and where each tuple is a trio of
(property, op, value), for example,[("n", ">", 10)]or[("n", ">", 10), ("x", "=", "alpha")].Valid op values are
>=,<,>,<=,=,!=andin.Backends must support sort orders where the sort order is a list of tuples, and where each tuple is a pair of
(property, direction), for example:[("n", "desc")].Valid direction values are
ascanddesc.The backend must construct and return
Keyinstances for each returned entity. Each serialized entity will be expected to have a dictionary index key with aKeyinstance as the value. This is required so that we do not have to know which underlying field the backend considers the “ID”.Parameters: - of_type (str) – Entity type to query for.
- query (tuple) – List of tuples representing a query.
- order (tuple) – List of tuples representing a sorting order.
- limit (int) – Positive integer reresenting the maximum number of entities to return.
- cursor (str) – Opaque value representing a position in the query result set.
Returns: Tuple of (entities, cursor, more) where
entitiesis a list of entities in their serialized form that they were saved as,cursoris an opaque string representing a position in the query result set, andmoreis a boolean representing whether or not a subsequent query, passing in the returned cursor, would produce more results.
-
fetch_async(of_type, query, order, limit, cursor, dataset=None, collection=None)[source]¶ Asynchronous variant of
fetch().Returns: A future representing the result tuple.
-
get(keys, dataset=None, collection=None)[source]¶ Get a list of Entities by their Keys.
Parameters: - keys (list) –
- dataset (str) –
- collection (str) –
Returns: A list of Entities.
-
get_async(keys, dataset=None, collection=None)[source]¶ Asynchronous variant of
get().Returns: A Future representing a list of Entities.
-
policy_class¶
-
-
bread.backends.stub.contains(x, xs)[source]¶ A version of contains that has the same semantics as datastore. Non-iterable values are checked for inclusion in
xs, iterables validate that at least one of their items is inxs.