Cursors#
Cursor’s allow for receiving more then 1 document at a time from your database.
- class alaric.Cursor(collection: AsyncIOMotorCollection, *, converter: Type[C] | None = None, encryption_key: bytes | None = None, encrypted_fields: EncryptedFields | None = None, automatic_hashed_fields: AutomaticHashedFields | None = None)#
- __aiter__()#
This style of iteration is also supported.
1cursor: Cursor = ... 2async for entry in cursor: 3 print(entry)
- __init__(collection: AsyncIOMotorCollection, *, converter: Type[C] | None = None, encryption_key: bytes | None = None, encrypted_fields: EncryptedFields | None = None, automatic_hashed_fields: AutomaticHashedFields | None = None)#
- Parameters:
collection (AsyncIOMotorCollection) – The motor collection
converter (Optional[Type[
C
]]) – An optional class to try to convert all data-types which return either Dict or List intoencrypted_fields (Optional[EncryptedFields]) – A list of fields to AES decrypt when encountered
encryption_key (Optional[bytes]) – The key to use for AES decryption
automatic_hashed_fields (Optional[AutomaticHashedFields]) – A list of fields to create an additional column in the db for with a hashed variant without exposing the hashed data to the end user.
Notes
This class is iterable using
async for
- copy() Cursor #
Returns a modifiable version of this cursor.
- Returns:
A new cursor instance
- Return type:
- set_filter(filter_data: Dict[str, Any] | Buildable | Filterable = ALL()) Cursor #
Set the filter for the cursor query.
- Parameters:
filter_data (Union[Dict[str, Any], Buildable, Filterable]) – A dictionary to use as a filter or
AQ
object.- Returns:
This cursor instance for method chaining.
- Return type:
- set_limit(limit: int = 0) Cursor #
Set a limit for how many documents should be returned in the query.
Use
0
to indicate no limit.- Parameters:
limit (int) –
How many documents should be returned.
Defaults to no limit.
- Returns:
This cursor instance for method chaining.
- Return type:
- Raises:
ValueError – You specified a negative number.
- set_projections(projections: Dict[str, Literal[0, 1]] | Projection | None = None) Cursor #
Define what data should be returned for each document in the result
- set_sort(order: List[Tuple[str, Any]] | Tuple[str, Any] | None = None) Cursor #
Set the sort order for returned results
- Parameters:
order (Optional[List[Tuple[str, Any]], Tuple[str, Any]]) – The order to sort by
- Returns:
This cursor instance for method chaining
- Return type:
- Raises:
ValueError – The passed value was not a list or tuple
.. code-block: – python: :linenos: import alaric # Lets sort by the count field Cursor.set_sort((“count”, alaric.Ascending)) … # Lets sort first by the count field, # then also by the backup_count field Cursor.set_sort([(“count”, alaric.Ascending), (“backup_count”, alaric.Descending)])