Ejemplo n.º 1
0
def row_proxy_to_dict(item: RowProxy):
    """
    RowProxy对象转换为字典
    :param item:
    :return:
    """
    item_out = ItemOut()
    if not isinstance(item, RowProxy):
        item_out.code = TYPE_TRANSFER_ERR
        item_out.msg = '类型转换错误'
        raise MyException(status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail=item_out)
    return dict(zip(item.keys(), item))
Ejemplo n.º 2
0
 def row2json(row: RowProxy) -> dict:
     """deal datetime to json error. """
     keys, values = row.keys(), row.values()
     new_row = {}
     try:
         for i in range(len(keys)):
             if isinstance(values[i], datetime):
                 values[i] = datetime.strftime(values[i],
                                               '%Y-%m-%d %H:%M:%S')
             new_row[keys[i]] = values[i]
     except Exception as e:
         logging.error(e)
     return new_row