nebula-python icon indicating copy to clipboard operation
nebula-python copied to clipboard

add wrapper/utils to help build paramters

Open wey-gu opened this issue 1 year ago • 2 comments

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 avatar May 04 '23 03:05 wey-gu

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

wey-gu avatar Sep 25 '23 11:09 wey-gu

done with #349

wey-gu avatar May 28 '24 04:05 wey-gu