xia_engine_firestore package
Submodules
xia_engine_firestore.base module
xia_engine_firestore.connection module
xia_engine_firestore.document module
xia_engine_firestore.fields module
Module contents
- class xia_engine_firestore.FirestoreEngine
Bases:
Engine
XIA Document Engine based on Firestore
- OPERATORS = {'__contains__': 'array_contains', '__ge__': '>=', '__gt__': '>', '__in__': 'in', '__le__': '<=', '__lt__': '<', '__ne__': '!=', '__not_in__': 'not-in'}
- classmethod batch(operations: list, originals: dict)
Data Batch Modification
The data will be updated at once or rolled back
- Parameters
operations – List of operations to be done * op: Operation type. “S” = set, “I” = create, “D” = delete, “U” = update * cls: Document Class * doc_id: Document ID * content: Document Content in Database form
originals – Dictionary (Help to roll back) * class: document class name * id: document id * content: document db form
- Returns
return True amd empty message if batch is successful, else False with error message
- classmethod create(document_class: Type[BaseDocument], db_content: dict, doc_id: Optional[str] = None)
Create a document
- Parameters
document_class (subclass of BaseDocument) – Document definition
db_content (dict) – content to be put to engine
doc_id (str) – Having predefined doc id, None means could be generated by engine
- Returns
Document ID
- classmethod delete(document_class: Type[BaseDocument], doc_id: str)
Delete a document by using id
- Parameters
document_class (subclass of BaseDocument) – Document definition
doc_id – Document ID
- classmethod drop(document_class: Type[BaseDocument])
Drop the given collection
- Parameters
document_class (subclass of BaseDocument) – Document definition
- engine_connector
alias of
Client
- engine_param: str = 'firestore'
- classmethod fetch(document_class: Type[BaseDocument], *args)
Get document one by one from a list of document id
- Returns
An iterator for id, document dictionary pair
- Comments:
when doc id is empty, it is probably because that the user only has partial read authorizations
- classmethod get(document_class: Type[BaseDocument], doc_id: str)
Get Document
- Parameters
document_class (subclass of BaseDocument) – Document definition
doc_id – Document ID
- Returns
Document content on python dict
- classmethod search(_document_class: Type[BaseDocument], *args, _acl_queries: list = None, _limit: int = 50, **kwargs)
Searching and yield document by document
- Parameters
_document_class (subclass of BaseDocument) – Document definition
*args – Unnamed arguments are document id
_acl_queries – Extra queries calculated from user’s Access Control List
_limit – Search result is limited
**kwargs – Named arguments are search string
- Notes for search string:
key, str pair: single value search
key, list pair: array_contains_any search
embedded search: a__b means b component of a. a.b means the key’s name is a.b
- operators: key is end with __op__. The following op are supported:
__eq__: Could ignore because it is a by default behavior
__lt__, __le__, __gt__, __ge__, __ne__: as is supposed by the name
__asc__, __desc__: the result will be ordered by the fields
- Attentions:
The complex query might raise compatible issues
- classmethod set(document_class: Type[BaseDocument], doc_id: str, db_content: dict)
Overwrite whole document
- Parameters
document_class (subclass of BaseDocument) – Document definition
doc_id – Document ID
db_content – content to be put to engine
- Returns
Document ID
- classmethod truncate(document_class: Type[BaseDocument])
Remove all data from the given collection
- Parameters
document_class (subclass of BaseDocument) – Document definition
- classmethod update(_document_class: Type[BaseDocument], _doc_id: str, **kwargs)
Update a document
- Parameters
_document_class (subclass of BaseDocument) – Document definition
_doc_id (str) – Document ID
**kwargs – Named keyword for update
- Returns
Updated data
- Notes for delete string:
embedded update: a__b means b component of a. a.b means the key’s name is a.b
- operators: key is end with __op__. The following op are supported:
__append__: Append an item to array
__remove__: Remove an item
__delete__: Delete the field
- classmethod update_doc_id(document_class: Type[BaseDocument], db_content: dict, old_id: str, new_id: str)
Update document id to new value
- Parameters
document_class (subclass of BaseDocument) – Document definition
db_content – content to be put to new engine
old_id – old document id
new_id – new document id
- Returns
new_document_id if the process is successful
- Comments:
By default, we return old id(not implemented). When it is implemented in the Engine, will return new document id