google.appengine.api.datastore_file_stub.DatastoreFileStub

Persistent stub for the Python datastore API.

Inherits From: BaseDatastore, BaseTransactionManager, BaseIndexManager, APIProxyStub, DatastoreStub, expected_type

Stores all entities in memory, and persists them to a file as pickled protocol buffers. A DatastoreFileStub instance handles a single app's data and is backed by files on disk.

app_id String
datastore_file String. Stores all entities across sessions. Use None not to use a file.
history_file DEPRECATE. No-op. </td> </tr><tr> <td>require_indexes</td> <td> Bool. Default isFalse. IfTrue, composite indexes must exist inindex.yamlfor queries that need them. </td> </tr><tr> <td>service_name</td> <td> Service name is expected for all calls. </td> </tr><tr> <td>trusted</td> <td> Bool. Default isFalse. IfTrue, this stub allows an app to access the data of another app. </td> </tr><tr> <td>consistency_policy</td> <td> The consistency policy to use orNoneto use the default. Consistency policies can be found indatastore_stub_util.*ConsistencyPolicy. </td> </tr><tr> <td>save_changes</td> <td> Bool. Default isTrue. If this stub should modifydatastore_filewhen entities are changed. </td> </tr><tr> <td>root_path</td> <td> String. The root path of the app. </td> </tr><tr> <td>use_atexit</td> <td> Bool. Indicates if the stub should save itself atexit. </td> </tr><tr> <td>auto_id_policy</td> <td> Enum. <a href="../../../../google/appengine/datastore/datastore_stub_util#SEQUENTIAL"><code>datastore_stub_util.SEQUENTIAL</code></a> or.SCATTERED`.

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 the datastore by deleting all currently stored entities and queries.

Close

View source

Closes the Datastore, writing any buffered data.

CreateIndex

View source

CreateRPC

View source

Creates RPC object instance.

Returns
An instance of RPC.

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.

MakeSyncCall

View source

The main RPC entry point. Service must be datastore_v3.

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.

QueryHistory

View source

Returns a dict that maps Query PBs to times they've been run.

Read

View source

Reads the datastore and history files into memory.

The in-memory query history is cleared, but the datastore is not cleared; the entities in the files are merged into the entities in memory. If you want them to overwrite the in-memory datastore, call Clear() before calling Read().

If the datastore file contains an entity with the same app name, kind, and key as an entity already in the datastore, the entity from the file overwrites the entity in the datastore.

Also sets each ID counter to one greater than the highest ID allocated so far in that counter's ID space.

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.

SetError

View source

Set an error condition that may be raised when calls made to stub.

If a method is specified, the error will only apply to that call. The error rate is applied to the method specified or all calls if method is not set.

Args
error An instance of apiproxy_errors.Error or None for no error.
method A string representing the method that the error will affect.
error_rate a number from [0, 1] that sets the chance of the error, defaults to 1.

SetTrusted

View source

Set/clear the trusted bit in the stub.

This bit indicates that the app calling the stub is trusted. A trusted app can write to datastores of other apps.

Args
trusted boolean.

Touch

View source

Applies all outstanding writes.

UpdateIndex

View source

Write

View source

Writes out the datastore and history files.

assertPbIsInitialized

View source

Raises an exception if the given PB is not initialized and valid.

DELETED 3
ERROR 4
READ_ERROR_MSG ('Data in %s is corrupt or a different version. Try running with the ' '--clear_datastore flag.\n' '%r')
READ_PB_EXCEPTIONS (<class 'google.protobuf.message.DecodeError'>, <class 'LookupError'>, <class 'TypeError'>, <class 'ValueError'>)
READ_PY250_MSG ('Are you using FloatProperty and/or GeoPtProperty? Unfortunately loading ' 'float values from the datastore file does not work with Python 2.5.0. Please ' 'upgrade to a newer Python 2.5 release or use the --clear_datastore flag.\n')
READ_WRITE 2
THREADSAFE False
WRITE_ONLY 1