[docs]classTransactionalSelect(Select):""" The TransactionalSelect class implements the Select base class for querying a chain-specific table within the Data Solutions system. It provides the structure for constructing and executing SQL queries using methods. """def_get_table(self,chain,table)->None:""" Return a SQLAlchemy Table object for the given chain and table name. :param chain: The chain name. :type chain: str :param table: The table name. :type table: str :return: A SQLAlchemy Table object. :rtype: Table :raises ValueException: If the chain or table does not exist in the database. """get_schemas_url=(f"{BASE_URL['base_url']}/{TRANSACTIONAL_ENDPOINTS['get_schemas']}")self.schemas:dict=issue_request(get_schemas_url,self.api_key)["schema"]chain_schema=self.schemas.get(chain)ifnotchain_schema:raiseValueException(f"Chain '{chain}' does not exist in the database. Check your input. "f"If you believe the inputted chain should exist, contact Data Solutions.")# If the chain exists, get the schema for the tableforlayer_tablesinchain_schema.values():table_data=next((_tablefor_tableinlayer_tablesiftablein_table),None)iftable_data:# If the table exists, return the tablecolumns=table_data[table]["schema"]table_columns=[Column(col["column"],type_mapping[col["type"]],comment=col["description"],)forcolincolumns]returnTable(f"{chain}.{table}",MetaData(),*table_columns)raiseValueException(f"Table '{table}' does not exist in the database for chain '{chain}'. Check your input. "f"If you believe the inputted table should exist, contact Data Solutions.")
[docs]defexecute(self,options:dict={},)->TransactionalQuery:""" Execute the query and return a Transactional object. :param options: The options for the query. :type options: dict :return: Transactional object. :rtype: Transactional """returnTransactionalQuery(self.api_key).__call__(self.sql().replace('"',""),options=options,)