from .interface import AnalyticsModuleInterface from .params import Param, ParamSchema class CollectionList(AnalyticsModuleInterface): description = """ """ inputs = [ ParamSchema, Param( "types_list", ptype=list, default_value=["source", "segment", "set"], values=["source", "enrichment", "algo", "set", "segment"], ), Param( "status_list", ptype=list, default_value=["finished", "enriching", "analyzing"], values=[ "finished", "processing", "enriching", "analyzing", "failed", "unknown", ], ), Param("collection_id", required=False), ] outputs = [ Param("id", int, idx=0), Param("name", str, idx=1), Param("collection_type", int, idx=2), ] @staticmethod def get_query( # type: ignore schema: str, types_list: list, status_list: list, collection_id: str = None, **kwargs, ) -> str: """Generate SQL query based on the fields""" where_collection = "" if collection_id is not None: where_collection = "AND id = %(collection_id)s " result_query = f"""SELECT id, name, collection_type FROM {schema}.collection WHERE collection_type IN({', '.join(f"'{tl}'" for tl in types_list)}) AND status IN({', '.join(f"'{tl}'" for tl in status_list)}) {where_collection}""" return result_query