core.db.types

The constants, global variables and container classes used in the datastore api

Attributes

KEY_SPECIAL_PROPERTY

The property name pointing to an entities key in a query

DATASTORE_BASE_TYPES

Types that can be used in a datastore query

current_db_access_log

If set to a set for the current thread/request, we'll log all entities / kinds accessed

KeyType

Alias that describes a key-type.

TOrders

TFilters

Classes

SortOrder

Create a collection of name/value pairs.

Key

The python representation of one datastore key. Unlike the original implementation, we don't store a

Entity

The python representation of one datastore entity. The values of this entity are stored inside this dictionary,

QueryDefinition

A single Query that will be run against the datastore.

Module Contents

core.db.types.KEY_SPECIAL_PROPERTY = '__key__'

The property name pointing to an entities key in a query

core.db.types.DATASTORE_BASE_TYPES

Types that can be used in a datastore query

core.db.types.current_db_access_log: contextvars.ContextVar[set[Key | str] | None]

If set to a set for the current thread/request, we’ll log all entities / kinds accessed

class core.db.types.SortOrder(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

Ascending = 1

Sort A->Z

Descending = 2

Sort Z->A

InvertedAscending = 3

Fetch Z->A, then flip the results (useful in pagination to go from a start cursor backwards)

InvertedDescending = 4

Fetch A->Z, then flip the results (useful in pagination)

class core.db.types.Key(*path_args, project=None, **kwargs)

Bases: google.cloud.datastore.Key

The python representation of one datastore key. Unlike the original implementation, we don’t store a reference to the project the key lives in. This is always expected to be the current project as ViUR does not support accessing data in multiple projects.

Parameters:

project (str | None)

__str__()
class core.db.types.Entity(key=None, exclude_from_indexes=None)

Bases: google.cloud.datastore.Entity

The python representation of one datastore entity. The values of this entity are stored inside this dictionary, while the meta-data (it’s key, the list of properties excluded from indexing and our version) as property values.

Parameters:
  • key (Optional[Key])

  • exclude_from_indexes (Optional[list[str]])

type core.db.types.KeyType = Key | str | int

Alias that describes a key-type.

type core.db.types.TOrders = list[tuple[str, SortOrder]]
type core.db.types.TFilters = dict[str, DATASTORE_BASE_TYPES | list[DATASTORE_BASE_TYPES]]
class core.db.types.QueryDefinition

A single Query that will be run against the datastore.

kind: str | None

The datastore kind to run the query on. Can be None for kindles queries.

filters: TFilters

A dictionary of constrains to apply to the query.

orders: TOrders | None

The list of fields to sort the results by.

distinct: list[str] | None = None

If set, a list of fields that we should return distinct values of

limit: int

The maximum amount of entities that should be returned

startCursor: str | None = None

If set, we’ll only return entities that appear after this cursor in the index.

endCursor: str | None = None

If set, we’ll only return entities up to this cursor in the index.

currentCursor: str | None = None

Will be set after this query has been run, pointing after the last entity returned

__post_init__()