View source on GitHub |
Persistent stub for the Python datastore API.
Inherits From: BaseDatastore
, BaseTransactionManager
, BaseIndexManager
, APIProxyStub
, DatastoreStub
, expected_type
google.appengine.api.datastore_file_stub.DatastoreFileStub(
app_id,
datastore_file,
history_file=None,
require_indexes=False,
service_name='datastore_v3',
trusted=False,
consistency_policy=None,
save_changes=True,
root_path=None,
use_atexit=True,
auto_id_policy=datastore_stub_util.SEQUENTIAL
)
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.
Args | |
---|---|
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 is False. If True, composite indexes
must exist in index.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 is False. If True, 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 or Noneto use the
default. Consistency policies can be found in datastore_stub_util.*ConsistencyPolicy.
</td>
</tr><tr>
<td> save_changes</td>
<td>
Bool. Default is True. If this stub should modify datastore_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
BeginTransaction(
app,
allow_multiple_eg,
previous_transaction=None,
mode=datastore_pb.BeginTransactionRequest.UNKNOWN
)
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
Clear()
Clears the datastore by deleting all currently stored entities and queries.
Close
Close()
Closes the Datastore, writing any buffered data.
CreateIndex
CreateIndex(
index, trusted=False, calling_app=None
)
CreateRPC
CreateRPC()
Creates RPC object instance.
Returns | |
---|---|
An instance of RPC. |
Delete
Delete(
raw_keys, cost, transaction=None, trusted=False, calling_app=None
)
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
DeleteIndex(
index, trusted=False, calling_app=None
)
Flush
Flush()
Applies all outstanding transactions.
Get
Get(
raw_keys,
transaction=None,
eventual_consistency=False,
trusted=False,
calling_app=None
)
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
GetIndexes(
app, trusted=False, calling_app=None
)
Get the CompositeIndex objects for the given app.
GetQueryCursor
GetQueryCursor(
raw_query, trusted=False, calling_app=None
)
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
GetTxn(
transaction, request_trusted, request_app
)
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
Groom()
Attempts to apply any outstanding transactions.
The consistency policy determins if a transaction should be applied.
MakeSyncCall
MakeSyncCall(
service, call, request, response, request_id=None
)
The main RPC entry point. Service must be datastore_v3.
Put
Put(
raw_entities, cost, transaction=None, trusted=False, calling_app=None
)
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
QueryHistory()
Returns a dict that maps Query PBs to times they've been run.
Read
Read()
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
SetAutoIdPolicy(
auto_id_policy
)
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
SetConsistencyPolicy(
policy
)
Set the consistency to use.
Causes all data to be flushed.
Args | |
---|---|
policy
|
A obj inheriting from BaseConsistencyPolicy. |
SetError
SetError(
error, method=None, error_rate=1
)
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
SetTrusted(
trusted
)
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
Touch(
raw_keys, trusted=False, calling_app=None
)
Applies all outstanding writes.
UpdateIndex
UpdateIndex(
index, trusted=False, calling_app=None
)
Write
Write()
Writes out the datastore and history files.
assertPbIsInitialized
assertPbIsInitialized(
pb
)
Raises an exception if the given PB
is not initialized and valid.