xia_engine.base.BaseDocument

class xia_engine.base.BaseDocument(**kwargs)

Bases: Base

The abstract definition of a documen

_uniques

Auto-calculated unique constraints of table

_address

Where and which part of the database could be found

Address Attributes:

_db: the database id, will be used to separate different data connection of the same data Engine _catalog: The target database, only data of the catalog will be operated. _scope: The target engine handles only part of data model. Scope has the same syntax as the searching criteria _tables: Could be used to overwrite the default table name. {“”: collection_name} abcd: All attributes not starting with ‘_’ will be passed to engine connector’s init method _abcd: Other “_” attributes could be used for each engine

Catalog Object Format:
Catalog object define the data field to be shown. The catalog is in the following format:
  • {field1: None, field2: None, field3: {sub-field1: None, sub-field2: None}}

  • field1, field2 is the top-level normal field

  • field3 is an embedded field/reference field/external field while sub-field1, sub-field2 is its fields

  • None means all fields

Scope Object Format:

Scope object only applies for the top level fields with multiple line following format. Condition of each line must be met. Each line has the following format:

  • {“fn”: field_name, “op”: operator, “val”: value}

  • operator could be one of {“==”, “<=”, “<”, “>=”, “>”, “in”}

__init__(**kwargs)

Methods

__init__(**kwargs)

action(action_name[, acl, payload])

Doing an action of a document

collection_action(action_name[, acl, payload])

Doing a collection level action

from_db([_engine])

Transform database data to internal data

from_display(**kwargs)

Transform Display data to internal data

get_actions()

Get action supported by this document

get_address([engine])

Get address for an engine

get_display_data([lazy, catalog, show_hidden])

Get Display data (visualized form of data)

get_id()

Get document id

get_raw_data()

Get Raw data (materialized form of data)

get_runtime_data()

Get Runtime data (calculated from raw data when runtime is activated)

get_sample()

Get a sample document data

set_address(engine, address_content)

to_db(*[, catalog, ignore_unknown, engine])

Translate the runtime data into raw data (materialized form of data)

validate()

Validate if all of the component of document follows the predefined rules

Attributes

OPERATORS

action(action_name: str, acl=None, payload: Optional[dict] = None)

Doing an action of a document

Parameters
  • action_name – The action name

  • acl – Access Control List

  • payload – Parameters of action

classmethod collection_action(action_name, acl=None, payload: Optional[dict] = None)

Doing a collection level action

Parameters
  • action_name – The action name

  • acl – Access Control List

  • payload – Parameters of action

classmethod from_db(_engine: Optional[Type[BaseEngine]] = None, **kwargs)

Transform database data to internal data

Parameters
  • _engine – engine to be used for convert data

  • **kwargs (object) – python dict got from system

Returns

python dict object

classmethod from_display(**kwargs)

Transform Display data to internal data

Parameters

**kwargs (object) – display object got from front end

Returns

python dict object

classmethod get_actions()

Get action supported by this document

Returns

Base]

Return type

dictionary[str

classmethod get_address(engine: Optional[Union[Type[BaseEngine], str]] = None)

Get address for an engine

Parameters

engine – Engine class or engine parameter name. default value is the engine attached to the document

Returns

Engine related parameters

get_display_data(lazy: bool = True, catalog: Optional[dict] = None, show_hidden: bool = False)

Get Display data (visualized form of data)

Parameters
  • lazy (bool) – Left the fields as is if they are not explicitly loaded

  • catalog (dict) – The catalog of display field in the following format: * {field1: false, field2: false, field3: {sub-field1: true, sub-field2: true}} * field1, field2 is the top-level normal field * field3 is an embedded field/reference field/external field while sub-field1, sub-field2 is its fields * True or false will override the lazy setting, none means using lazy settings

  • show_hidden (bool) – If hidden value should be shown or not

Returns

python dict object

Notes

We will return the detail form if it is possible

get_id()

Get document id

Returns

Document ID

Return type

str

get_raw_data()

Get Raw data (materialized form of data)

Returns

python dict object

get_runtime_data()

Get Runtime data (calculated from raw data when runtime is activated)

Returns

python dict object

classmethod get_sample()

Get a sample document data

to_db(*, catalog: Optional[dict] = None, ignore_unknown: bool = False, engine: Optional[Type[BaseEngine]] = None)

Translate the runtime data into raw data (materialized form of data)

Parameters
  • catalog (dict) – Data catalog to be parsed

  • ignore_unknown (bool) – When a field is not defined in the document, should we send it back to the database

  • engine – engine to be used for db data conversion

Returns

python dict object

validate()

Validate if all of the component of document follows the predefined rules

Returns

Always None. No exception raised means the validation passed