Beispiel #1
0
 def _count(self, **kwargs) -> int:
     return match(
         node(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(**kwargs),
         ), ).ret(func.count(self.variable).as_("count"), )
Beispiel #2
0
 def _retrieve(self, identifier: str) -> Cypher:
     return match(
         node(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(
                 id=str(identifier), ),
         ), ).ret(expr(self.variable), )
 def _create(self, instance: R) -> Cypher:
     return match(
         node(
             "in",
             instance.in_class().label(),
             properties=dict(id=instance.in_id, ),
         ), ).match(
             node(
                 "out",
                 instance.out_class().label(),
                 properties=dict(id=instance.out_id, ),
             ), ).merge(
                 node("in", ).rel_in(
                     self.variable,
                     instance.__class__.label(),
                     properties=instance.properties(),
                 ).node("out", ), ).ret(expr(self.variable), )
Beispiel #4
0
def test_readme_query():
    query = match(node("person", "Person").rel_in().node("pet", "Pet")).ret(
        "person",
        "pet",
    )
    assert_that(
        str(query),
        is_(
            equal_to(
                "MATCH (person:Person)-[]->(pet:Pet) RETURN person, pet", )),
    )
Beispiel #5
0
 def _search(self, limit=None, offset=None, **kwargs) -> Cypher:
     return match(
         node(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(**kwargs),
         ), ).ret(
             expr(self.variable),
             limit=limit,
             skip=offset,
         )
Beispiel #6
0
def test_readme_update():
    query = match(node("alice", "Person", {"name": "Alice"}), ).match(
        node("bob", "Person", {"name": "Bob"}), ).merge(
            node("bob").rel_in(types="IS_FRIENDS_WITH").node("alice"), ).merge(
                node("alice").rel_in(types="IS_FRIENDS_WITH").node("bob"), )

    assert_that(
        str(query),
        is_(
            equal_to("MATCH (alice:Person {name: $alice_name}) "
                     "MATCH (bob:Person {name: $bob_name}) "
                     "MERGE (bob)-[:IS_FRIENDS_WITH]->(alice) "
                     "MERGE (alice)-[:IS_FRIENDS_WITH]->(bob)")),
    )
    assert_that(
        dict(query),
        is_(equal_to(dict(
            alice_name="Alice",
            bob_name="Bob",
        ))),
    )
 def _count(self, **kwargs) -> Cypher:
     return match(
         node(
             "in",
             self.model_class.in_class().label(),
         ).rel_in(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(**kwargs),
         ).node(
             "out",
             self.model_class.out_class().label(),
         ), ).ret(func.count(self.variable).as_("count"), )
 def _retrieve(self, identifier: str) -> Cypher:
     return match(
         node(
             "in",
             self.model_class.in_class().label(),
         ).rel_in(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(
                 id=str(identifier), ),
         ).node(
             "out",
             self.model_class.out_class().label(),
         ), ).ret(self.variable, )
Beispiel #9
0
 def _create(self, instance: N) -> Cypher:
     assignments = parameters(
         key_prefix=self.variable,
         name_prefix=self.variable,
         **self._value_properties(instance),
     )
     return merge(
         node(
             self.variable,
             instance.__class__.label(),
             properties=self._unique_properties(instance),
         ), ).set(
             assignments[0],
             *assignments[1:],
         ).ret(expr(self.variable), )
 def _search(self, limit=None, offset=None, **kwargs) -> Cypher:
     return match(
         node(
             "in",
             self.model_class.in_class().label(),
         ).rel_in(
             self.variable,
             self.model_class.label(),
             properties=self.model_class.matching_properties(**kwargs),
         ).node(
             "out",
             self.model_class.out_class().label(),
         ), ).ret(
             self.variable,
             limit=limit,
             skip=offset,
         )
Beispiel #11
0
def test_api():
    ast = match(
        node(
            "foo",
            "FOO",
            properties=properties(parameters(
                name_prefix="foo",
                bar="baz",
            ), ),
        ).rel_in(
            None,
            "Bar",
        ).node(
            "baz",
            "BAZ",
            properties=properties(parameters(
                name_prefix="baz",
                bar="foo",
            ), ),
        ), ).delete(
            "foo",
            "baz",
        ).ret(
            "foo",
            "baz",
            order=asc("foo", "bar"),
        )

    assert_that(
        str(ast),
        is_(
            equal_to(
                "MATCH (foo:FOO {bar: $foo_bar})-[:Bar]->(baz:BAZ {bar: $baz_bar}) "
                "DELETE foo, baz "
                "RETURN foo, baz ORDER BY foo ASCENDING, bar ASCENDING", )),
    )
    assert_that(
        dict(ast),
        is_(equal_to(dict(
            foo_bar="baz",
            baz_bar="foo",
        ))),
    )