From f070a8b5ec35ba1972c13349962622d90f2b3588 Mon Sep 17 00:00:00 2001 From: Roei Levi Date: Sun, 2 Jul 2023 19:48:17 +0300 Subject: [PATCH 1/2] docs: fix readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9dc5d5d..0baac47 100644 --- a/README.md +++ b/README.md @@ -61,13 +61,13 @@ Two queries can be combined to a create a new one. ```python qb = QueryBuilder() query1 = qb.match().node(labels='Person', ref_name='p').with_('p') -query2 = qb.match().node(labels='Person', ref_name='q').related_to('friend_of').node('p') +query2 = qb.match().node(labels='Person', ref_name='q').related_to('friend_of').node(ref_name='p') query = query1 + query2 print(query) ``` This snippet will output the following Cypher query: ```cypher -MATCH (p: Person) WITH p MATCH (q: Person)-[: friend_of]->(: p) +MATCH (p: Person) WITH p MATCH (q: Person)-[: friend_of]->(p) ``` ### Prerequisites From 5e2f3d592f7216cd3b2caa7acf4b7ca6e8a4442c Mon Sep 17 00:00:00 2001 From: Roei Levi Date: Thu, 6 Jul 2023 14:04:41 +0300 Subject: [PATCH 2/2] feat: unify apis for relationships --- src/cymple/builder.py | 168 +++++++++--------- .../internal/declarations/relation.json | 56 +++--- .../declarations/relation_after_merge.json | 56 +++--- src/cymple/internal/overloads/relation.py | 50 +++--- src/cymple/version.py | 2 +- src/samples/basic.py | 4 +- tests/unit/test_clauses.py | 6 +- 7 files changed, 178 insertions(+), 164 deletions(-) diff --git a/src/cymple/builder.py b/src/cymple/builder.py index 6863f65..c09e556 100644 --- a/src/cymple/builder.py +++ b/src/cymple/builder.py @@ -358,7 +358,7 @@ def procedure(self, literal_procedure: str): class Relation(Query): """A class for representing a "RELATION" clause.""" - def related(self, label: str = None, ref_name: str = None, properties: dict = None, **kwargs): + def related(self, label: str = None, ref_name: str = None, properties: dict = None, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate an undirectional (i.e. --) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -368,15 +368,19 @@ def related(self, label: str = None, ref_name: str = None, properties: dict = No :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to None :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAvailable """ - return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, **kwargs)) + return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def related_to(self, label: str = None, ref_name: str = None, properties: dict = {}, **kwargs): + def related_to(self, label: str = None, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a forward (i.e. -->) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -386,15 +390,19 @@ def related_to(self, label: str = None, ref_name: str = None, properties: dict = :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAvailable """ - return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, **kwargs)) + return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def related_from(self, label: str = None, ref_name: str = None, properties: dict = {}, **kwargs): + def related_from(self, label: str = None, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a backward (i.e. <--) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -404,46 +412,19 @@ def related_from(self, label: str = None, ref_name: str = None, properties: dict :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict - :param **kwargs: kwargs - :type **kwargs - - :return: A Query object with a query that contains the new clause. - :rtype: RelationAvailable - """ - return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, **kwargs)) - - def related_variable_len(self, label: str = None, ref_name: str = None, min_hops: int = -1, max_hops: int = -1): - """Concatenate a uni-directional graph Relationship, with a variable path length. - - :param label: The relationship label (type) in the DB, defaults to None - :type label: str - :param ref_name: A reference name to be used later in the rest of the query, defaults to None - :type ref_name: str - :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to -1 + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 :type min_hops: int - :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to -1 + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 :type max_hops: int + :param **kwargs: kwargs + :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAvailable """ - min_hops_str = '' if min_hops == -1 else str(min_hops) - max_hops_str = '' if max_hops == -1 else str(max_hops) - - relation_type = '' if label is None else f': {label}' - relation_ref_name = '' if ref_name is None else f'{ref_name}' - - relation_length = '*' if min_hops == -1 and max_hops == - \ - 1 else (f'*{min_hops_str}'if min_hops == max_hops else f'*{min_hops_str}..{max_hops_str}') - - if relation_length: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_length}]' - else: - realtion_str = '' - - return RelationAvailable(self.query + f'-{realtion_str}-') + return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: dict = {}, **kwargs): + def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a graph Relationship (private method). :param direction: The relationship direction, can one of 'forward', 'backward' - otherwise unidirectional @@ -455,33 +436,48 @@ def _directed_relation(self, direction: str, label: str, ref_name: str = None, p :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAvailable """ + min_hops_str = '' if min_hops == -1 else str(min_hops) + max_hops_str = '' if max_hops == -1 else str(max_hops) + relation_type = '' if label is None else f': {label}' relation_ref_name = '' if ref_name is None else f'{ref_name}' relation_properties = f' {{{Properties(properties).to_str(**kwargs)}}}' if properties else '' + if min_hops == 1 and max_hops == 1: + relation_length = '' + elif min_hops == -1 and max_hops == -1: + relation_length = '*' + elif min_hops == max_hops: + relation_length = f'*{min_hops_str}' + else: + relation_length = f'*{min_hops_str}..{max_hops_str}' - if relation_ref_name or relation_type: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_properties}]' + if relation_ref_name or relation_type or relation_length or relation_properties: + relation_str = f'[{relation_ref_name}{relation_type}{relation_length}{relation_properties}]' else: - realtion_str = '' + relation_str = '' if direction == 'forward': - return f'-{realtion_str}->' + return f'-{relation_str}->' if direction == 'backward': - return f'<-{realtion_str}-' + return f'<-{relation_str}-' - return f'-{realtion_str}-' + return f'-{relation_str}-' class RelationAfterMerge(Query): """A class for representing a "RELATION AFTER MERGE" clause.""" - def related(self, label: str = None, ref_name: str = None, properties: dict = None, **kwargs): + def related(self, label: str = None, ref_name: str = None, properties: dict = None, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate an undirectional (i.e. --) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -491,15 +487,19 @@ def related(self, label: str = None, ref_name: str = None, properties: dict = No :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to None :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAfterMergeAvailable """ - return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, **kwargs)) + return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def related_to(self, label: str = None, ref_name: str = None, properties: dict = {}, **kwargs): + def related_to(self, label: str = None, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a forward (i.e. -->) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -509,15 +509,19 @@ def related_to(self, label: str = None, ref_name: str = None, properties: dict = :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAfterMergeAvailable """ - return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, **kwargs)) + return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def related_from(self, label: str = None, ref_name: str = None, properties: dict = {}, **kwargs): + def related_from(self, label: str = None, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a backward (i.e. <--) graph Relationship, which may be filtered. :param label: The relationship label (type) in the DB, defaults to None @@ -527,46 +531,19 @@ def related_from(self, label: str = None, ref_name: str = None, properties: dict :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict - :param **kwargs: kwargs - :type **kwargs - - :return: A Query object with a query that contains the new clause. - :rtype: RelationAfterMergeAvailable - """ - return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, **kwargs)) - - def related_variable_len(self, label: str = None, ref_name: str = None, min_hops: int = -1, max_hops: int = -1): - """Concatenate a uni-directional graph Relationship, with a variable path length. - - :param label: The relationship label (type) in the DB, defaults to None - :type label: str - :param ref_name: A reference name to be used later in the rest of the query, defaults to None - :type ref_name: str - :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to -1 + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 :type min_hops: int - :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to -1 + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 :type max_hops: int + :param **kwargs: kwargs + :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAfterMergeAvailable """ - min_hops_str = '' if min_hops == -1 else str(min_hops) - max_hops_str = '' if max_hops == -1 else str(max_hops) - - relation_type = '' if label is None else f': {label}' - relation_ref_name = '' if ref_name is None else f'{ref_name}' - - relation_length = '*' if min_hops == -1 and max_hops == - \ - 1 else (f'*{min_hops_str}'if min_hops == max_hops else f'*{min_hops_str}..{max_hops_str}') - - if relation_length: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_length}]' - else: - realtion_str = '' - - return RelationAvailable(self.query + f'-{realtion_str}-') + return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, min_hops, max_hops, **kwargs)) - def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: dict = {}, **kwargs): + def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): """Concatenate a graph Relationship (private method). :param direction: The relationship direction, can one of 'forward', 'backward' - otherwise unidirectional @@ -578,27 +555,42 @@ def _directed_relation(self, direction: str, label: str, ref_name: str = None, p :param properties: A dict representing the set of properties by which the relationship is filtered, defaults to {} :type properties: dict + :param min_hops: The minimal desired number of hops (set -1 for maximum boundary only), defaults to 1 + :type min_hops: int + :param max_hops: The maximal desired number of hops (set -1 for minimal boundary only), defaults to 1 + :type max_hops: int :param **kwargs: kwargs :type **kwargs :return: A Query object with a query that contains the new clause. :rtype: RelationAfterMergeAvailable """ + min_hops_str = '' if min_hops == -1 else str(min_hops) + max_hops_str = '' if max_hops == -1 else str(max_hops) + relation_type = '' if label is None else f': {label}' relation_ref_name = '' if ref_name is None else f'{ref_name}' relation_properties = f' {{{Properties(properties).to_str(**kwargs)}}}' if properties else '' + if min_hops == 1 and max_hops == 1: + relation_length = '' + elif min_hops == -1 and max_hops == -1: + relation_length = '*' + elif min_hops == max_hops: + relation_length = f'*{min_hops_str}' + else: + relation_length = f'*{min_hops_str}..{max_hops_str}' - if relation_ref_name or relation_type: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_properties}]' + if relation_ref_name or relation_type or relation_length or relation_properties: + relation_str = f'[{relation_ref_name}{relation_type}{relation_length}{relation_properties}]' else: - realtion_str = '' + relation_str = '' if direction == 'forward': - return f'-{realtion_str}->' + return f'-{relation_str}->' if direction == 'backward': - return f'<-{realtion_str}-' + return f'<-{relation_str}-' - return f'-{realtion_str}-' + return f'-{relation_str}-' class Remove(Query): diff --git a/src/cymple/internal/declarations/relation.json b/src/cymple/internal/declarations/relation.json index 8b15c8e..6bbd390 100644 --- a/src/cymple/internal/declarations/relation.json +++ b/src/cymple/internal/declarations/relation.json @@ -20,6 +20,16 @@ "default": "None", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } @@ -44,6 +54,16 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } @@ -68,34 +88,18 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, - "**kwargs": { - "description": "kwargs" - } - } - }, - { - "name": "related_variable_len", - "docstring_summary": "Concatenate a uni-directional graph Relationship, with a variable path length.", - "args": { - "label": { - "type": "str", - "default": "None", - "description": "The relationship label (type) in the DB" - }, - "ref_name": { - "type": "str", - "default": "None", - "description": "A reference name to be used later in the rest of the query" - }, "min_hops": { "type": "int", "description": "The minimal desired number of hops (set -1 for maximum boundary only)", - "default": "-1" + "default": "1" }, "max_hops": { "type": "int", "description": "The maximal desired number of hops (set -1 for minimal boundary only)", - "default": "-1" + "default": "1" + }, + "**kwargs": { + "description": "kwargs" } } }, @@ -121,6 +125,16 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } diff --git a/src/cymple/internal/declarations/relation_after_merge.json b/src/cymple/internal/declarations/relation_after_merge.json index c977155..d3d6e86 100644 --- a/src/cymple/internal/declarations/relation_after_merge.json +++ b/src/cymple/internal/declarations/relation_after_merge.json @@ -20,6 +20,16 @@ "default": "None", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } @@ -44,6 +54,16 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } @@ -68,34 +88,18 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, - "**kwargs": { - "description": "kwargs" - } - } - }, - { - "name": "related_variable_len", - "docstring_summary": "Concatenate a uni-directional graph Relationship, with a variable path length.", - "args": { - "label": { - "type": "str", - "default": "None", - "description": "The relationship label (type) in the DB" - }, - "ref_name": { - "type": "str", - "default": "None", - "description": "A reference name to be used later in the rest of the query" - }, "min_hops": { "type": "int", "description": "The minimal desired number of hops (set -1 for maximum boundary only)", - "default": "-1" + "default": "1" }, "max_hops": { "type": "int", "description": "The maximal desired number of hops (set -1 for minimal boundary only)", - "default": "-1" + "default": "1" + }, + "**kwargs": { + "description": "kwargs" } } }, @@ -121,6 +125,16 @@ "default": "{}", "description": "A dict representing the set of properties by which the relationship is filtered" }, + "min_hops": { + "type": "int", + "description": "The minimal desired number of hops (set -1 for maximum boundary only)", + "default": "1" + }, + "max_hops": { + "type": "int", + "description": "The maximal desired number of hops (set -1 for minimal boundary only)", + "default": "1" + }, "**kwargs": { "description": "kwargs" } diff --git a/src/cymple/internal/overloads/relation.py b/src/cymple/internal/overloads/relation.py index ef7a173..f243c6a 100644 --- a/src/cymple/internal/overloads/relation.py +++ b/src/cymple/internal/overloads/relation.py @@ -1,51 +1,45 @@ -def related(self, label: str, ref_name: str = None, properties: dict = None, **kwargs): - return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, **kwargs)) +def related(self, label: str, ref_name: str = None, properties: dict = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): + return RelationAvailable(self.query + self._directed_relation('none', label, ref_name, properties, min_hops, max_hops, **kwargs)) -def related_to(self, label: str, ref_name: str = None, properties: str = {}, **kwargs): - return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, **kwargs)) +def related_to(self, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): + return RelationAvailable(self.query + self._directed_relation('forward', label, ref_name, properties, min_hops, max_hops, **kwargs)) -def related_from(self, label: str, ref_name: str = None, properties: str = {}, **kwargs): - return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, **kwargs)) +def related_from(self, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): + return RelationAvailable(self.query + self._directed_relation('backward', label, ref_name, properties, min_hops, max_hops, **kwargs)) -def related_variable_len(self, label: str, ref_name: str = None, min_hops: int = -1, max_hops: int = -1): +def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: str = {}, min_hops: int = 1, max_hops: int = 1, **kwargs): min_hops_str = '' if min_hops == -1 else str(min_hops) max_hops_str = '' if max_hops == -1 else str(max_hops) - relation_type = '' if label is None else f': {label}' - relation_ref_name = '' if ref_name is None else f'{ref_name}' - - relation_length = '*' if min_hops == -1 and max_hops == -1 else (f'*{min_hops_str}'if min_hops == max_hops else f'*{min_hops_str}..{max_hops_str}') - - if relation_length: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_length}]' - else: - realtion_str = '' - - return RelationAvailable(self.query + f'-{realtion_str}-') - - -def _directed_relation(self, direction: str, label: str, ref_name: str = None, properties: str = {}, **kwargs): relation_type = '' if label is None else f': {label}' relation_ref_name = '' if ref_name is None else f'{ref_name}' relation_properties = f' {{{Properties(properties).to_str(**kwargs)}}}' if properties else '' - - if relation_ref_name or relation_type: - realtion_str = f'[{relation_ref_name}{relation_type}{relation_properties}]' + if min_hops == 1 and max_hops == 1: + relation_length = '' + elif min_hops == -1 and max_hops == -1: + relation_length = '*' + elif min_hops == max_hops: + relation_length = f'*{min_hops_str}' + else: + relation_length = f'*{min_hops_str}..{max_hops_str}' + + if relation_ref_name or relation_type or relation_length or relation_properties: + relation_str = f'[{relation_ref_name}{relation_type}{relation_length}{relation_properties}]' else: - realtion_str = '' + relation_str = '' if direction == 'forward': - return f'-{realtion_str}->' + return f'-{relation_str}->' if direction == 'backward': - return f'<-{realtion_str}-' + return f'<-{relation_str}-' - return f'-{realtion_str}-' + return f'-{relation_str}-' __all__ = ['related', 'related_to', 'related_from', '_directed_relation'] diff --git a/src/cymple/version.py b/src/cymple/version.py index 6744925..2d6a4ec 100644 --- a/src/cymple/version.py +++ b/src/cymple/version.py @@ -1,3 +1,3 @@ """Version information for Cymple""" -__version__: str = "0.9.0" +__version__: str = "0.10.0" diff --git a/src/samples/basic.py b/src/samples/basic.py index 09fce8c..d233d5e 100644 --- a/src/samples/basic.py +++ b/src/samples/basic.py @@ -46,7 +46,7 @@ def get_all_nodes_related_by_fixed_num_of_hops(src_node_labels: Union[List[str], return (QueryBuilder() .match() .node(labels=src_node_labels) - .related_variable_len(min_hops=num_hops, max_hops=num_hops) + .related(min_hops=num_hops, max_hops=num_hops) .node(labels=dst_node_labels, ref_name=dst_node_name) .return_literal(literal=dst_node_name) ) @@ -56,7 +56,7 @@ def get_all_nodes_related_by_varying_num_of_hops(src_node_labels: Union[List[str return (QueryBuilder() .match() .node(labels=src_node_labels) - .related_variable_len(min_hops=min_hops, max_hops=max_hops) + .related(min_hops=min_hops, max_hops=max_hops) .node(labels=dst_node_labels, ref_name=dst_node_name) .return_literal(literal=dst_node_name) ) diff --git a/tests/unit/test_clauses.py b/tests/unit/test_clauses.py index 2e7d73e..d464847 100644 --- a/tests/unit/test_clauses.py +++ b/tests/unit/test_clauses.py @@ -22,9 +22,9 @@ 'RELATION (forward)': qb.reset().match().node().related_to().node(), 'RELATION (backward)': qb.reset().match().node().related_from().node(), 'RELATION (unidirectional)': qb.reset().match().node().related().node(), - 'RELATION (variable length)': qb.reset().match().node().related_variable_len(min_hops=1, max_hops=2).node(), - 'RELATION (variable length, empty)': qb.reset().match().node().related_variable_len().node(), - 'RELATION (variable length, with label)': qb.reset().match().node().related_variable_len(label='Relation', ref_name='rel', min_hops=1, max_hops=2).node(), + 'RELATION (variable length)': qb.reset().match().node().related(min_hops=1, max_hops=2).node(), + 'RELATION (variable length, empty)': qb.reset().match().node().related(min_hops=-1, max_hops=-1).node(), + 'RELATION (variable length, with label)': qb.reset().match().node().related(label='Relation', ref_name='rel', min_hops=1, max_hops=2).node(), 'RETURN (literal)': qb.reset().match().node(ref_name='n').return_literal('n'), 'RETURN (mapping)': qb.reset().match().node(ref_name='n').return_mapping(('n.name', 'name')), 'RETURN (mapping, list)': qb.reset().match().node(ref_name='n').return_mapping([('n.name', 'name'), ('n.age', 'age')]),