google.appengine.datastore.datastore_stub_util.BaseDatastore

A base implementation of a Datastore.

Inherits From: BaseTransactionManager, BaseIndexManager, expected_type

This class implements common functions associated with a datastore and enforces security restrictions passed on by a stub or client. It is designed to be shared by any number of threads or clients serving any number of apps.

If an app is not specified explicitly it is pulled from the env and assumed to be untrusted.

Methods

BeginTransaction

View source

Start a transaction on the given app.

Args
app A string representing the app for which to start the transaction.
allow_multiple_eg True if transactions can span multiple entity groups.
previous_transaction The transaction to reset.
mode Mode of the transaction.

Returns
A datastore_pb.Transaction() for the created transaction

Clear

View source

Clears out all stored values.

Close

View source

Closes the Datastore, writing any buffered data.

CreateIndex

View source

Delete

View source

Deletes the entities associated with the given keys.

Args
raw_keys A list of unverified entity_pb2.Reference objects.
cost Out param. The cost of putting the provided entities.
transaction The datastore_pb.Transaction() to use or None.
trusted If the calling app is trusted.
calling_app The app requesting the results or None to pull the app from the environment.

Returns
A list of versions numbers at which the entities were deleted, one for each given keys. Every version numbers are None if a transaction is given.

DeleteIndex

View source

Flush

View source

Applies all outstanding transactions.

Get

View source

Get the entity records for the given keys.

Args
raw_keys A list of unverified entity_pb2.Reference objects.
transaction The datastore_pb.Transaction to use or None.
eventual_consistency If we should allow stale, potentially inconsistent results.
trusted If the calling app is trusted.
calling_app The app requesting the results or None to pull the app from the environment.

Returns
A list containing the records in the same order as the list of keys.

GetIndexes

View source

Get the CompositeIndex objects for the given app.

GetQueryCursor

View source

Execute a query.

Args
raw_query The non-validated datastore_pb.Query to run.
trusted If the calling app is trusted.
calling_app The app requesting the results or None to pull the app from the environment.

Returns
A BaseCursor that can be used to retrieve results.

GetTxn

View source

Gets the LiveTxn object associated with the given transaction.

Args
transaction The datastore_pb.Transaction() to look up.
request_trusted A boolean indicating If the requesting app is trusted.
request_app A string representing the app making the request.

Returns
The associated LiveTxn object.

Groom

View source

Attempts to apply any outstanding transactions.

The consistency policy determins if a transaction should be applied.

Put

View source

Writes the given given entities.

Updates an entity's key and entity_group in place if needed

Args
raw_entities A list of unverified entity_pb2.EntityProto objects.
cost Out param. The cost of putting the provided entities.
transaction The datastore_pb.Transaction() to use or None.
trusted If the calling app is trusted.
calling_app The app requesting the results or None to pull the app from the environment.

Returns
A list of tuple (entity_pb2.Reference, version number) that indicates where each entity was stored and at which version. When a transaction is provided, all version numbers are None.

SetAutoIdPolicy

View source

Set value of _auto_id_policy flag (default SEQUENTIAL).

SEQUENTIAL auto ID assignment behavior will eventually be deprecated and the default will be SCATTERED.

Args
auto_id_policy string constant.

Raises
TypeError if auto_id_policy is not one of SEQUENTIAL or SCATTERED.

SetConsistencyPolicy

View source

Set the consistency to use.

Causes all data to be flushed.

Args
policy A obj inheriting from BaseConsistencyPolicy.

Touch

View source

Applies all outstanding writes.

UpdateIndex

View source

Write

View source

Writes the datastore to disk.

DELETED 3
ERROR 4
READ_WRITE 2
WRITE_ONLY 1