I want to populate a graph with vertices and edges yet I’ve found in the docs multiple ways of doing this and it is unclear to me what the pros and cons of each one are. There’s:
- create_vertex(), 2) .save(), 3) .create()...execute()
I want to populate a graph with vertices and edges yet I’ve found in the docs multiple ways of doing this and it is unclear to me what the pros and cons of each one are. There’s:
Query modules are extensions of the Cypher query language. It is useful if you if you need to expand the Cypher language with custom procedures. Memgraph provides public APIs for writing custom query modules in Python, C/C++ and Rust. Maybe this is not the best first step you take to populate a graph with nodes and relationships.
Using OGM or Object Graph Mapper you are able to create classes representing the nodes and relationships. It is useful if you have a certain database structure as you are able to define node properties. After creating classes, saving nodes and creating realtionships between them, OGM makes fetching and further using node properties easy. On instance of defined graph object with the help of the GQLAlchemy (OGM), you can call save(db) method to save nodes or relationships to a database. It is not necessary to use OGM if you don’t have a strict schema.
Query builder is useful if you are not that familiar with Cypher query language, since it helps you build and execute a Cypher query. With Cypher, you can create a node by running
CREATE (n:Label {name: 'Leslie'})
directly from you Python code with
`memgraph.execute(“CREATE (n:Label {name: 'Leslie'});”)`
or by using the query builder:
`from gqlalchemy import Create
query = Create().node(labels="Person", name="Leslie").execute()`
If you want to create a relationship between two nodes, you can do it like this:
`CREATE (:Person {name: 'Leslie'})-[:FRIENDS_WITH]->(:Person {name: 'Ron'});`
and execute it with
`memgraph.execute`
or by using query builder:
`from gqlalchemy import Create
query = Create()
.node(labels="Person", name="Leslie")
.to(relationship_type="FRIENDS_WITH")
.node(labels="Person", name="Ron")
.execute()`