vesoft-inc / nebula-python

Client API of Nebula Graph in Python
193 stars 78 forks source link

add wrapper/utils to help build paramters #273

Open wey-gu opened 1 year ago

wey-gu commented 1 year ago

i.e., it took me some time to figure out how to build a proper Nlist of strings to be passed to session_pool.execute_parameter(), I will wrap it as a utils later.

def prepare_subjs_param(subjs: Optional[List[str]]) -> dict:
    """Prepare parameters for query."""
    if subjs is None:
        return {}
    from nebula3.common import ttypes

    subjs_list = []
    subjs_byte = ttypes.Value()
    for subj in subjs:
        if not isinstance(subj, str):
            raise TypeError(f"Subject should be str, but got {type(subj).__name__}.")
        subj_byte = ttypes.Value()
        subj_byte.set_sVal(subj)
        subjs_list.append(subj_byte)
    subjs_nlist = ttypes.NList(values=subjs_list)
    subjs_byte.set_lVal(subjs_nlist)
    return {"subjs": subjs_byte}
wey-gu commented 1 year ago

For anyone who would like to impl. this, I will reassign to you.

wey-gu commented 5 months ago

done with #349