View source on GitHub |
A base implementation of a Datastore.
Inherits From: BaseTransactionManager
, BaseIndexManager
, expected_type
google.appengine.datastore.datastore_stub_util.BaseDatastore(
require_indexes=False,
consistency_policy=None,
use_atexit=True,
auto_id_policy=SEQUENTIAL
)
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
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 out all stored values.
Close
Close()
Closes the Datastore, writing any buffered data.
CreateIndex
CreateIndex(
index, trusted=False, calling_app=None
)
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.
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. |
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. |
Touch
Touch(
raw_keys, trusted=False, calling_app=None
)
Applies all outstanding writes.
UpdateIndex
UpdateIndex(
index, trusted=False, calling_app=None
)
Write
Write()
Writes the datastore to disk.
Class Variables | |
---|---|
DELETED |
3
|
ERROR |
4
|
READ_WRITE |
2
|
WRITE_ONLY |
1
|