[docs]classStringify:""" This class contains functions to transform python objects into formatted string params so they can be used to query Data Solutions' databases without needing to be transformed manually by the user. """
[docs]deflists(self,_list:list)->str:""" Convert a list to a formatted string param. :param list: The list to be converted. :type list: list :raises Exception: Raises an exception if a list type is not submitted. :raises Exception: If lists do not contain the right types. :return: The converted list. :rtype: str """ifnotisinstance(_list,list):raiseBadRequest("Incorrect type. Supply a list.",)type=get_list_type(_list)iftype==intortype==boolortype==floatortype==decimal:returnf"({', '.join(map(str,_list))})"iftype==str:result="("fori,elementinenumerate(_list):ifi>0:result+=", "result+=f"'{element}'"result+=")"returnresult
[docs]defcolumns(self,columns:list)->str:""" Convert a column select list to a formatted string param. :param list: The column select list object to be converted. :type list: list :return: The converted column select list. :rtype: str """type=get_list_type(columns)iftype!=str:raiseBadRequest("Columns must be a string list")return", ".join(columns)
[docs]defdatetimes(self,_datetime:datetime.datetime)->str:""" Convert a datetime object to a formatted string param. :param list: The datetime object to be converted. :type list: list :return: The converted datetime object. :rtype: str """ifnotisinstance(_datetime,datetime.datetime):raiseBadRequest("Incorrect type. Supply a datetime.datetime object.")returnf"'{_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')}'"