DEV Community

Cover image for Mastering Apache AGE: A Comprehensive Tutorial for Crafting Dynamic Graphs with Nodes and Edges
Hassam Abdullah
Hassam Abdullah

Posted on

Mastering Apache AGE: A Comprehensive Tutorial for Crafting Dynamic Graphs with Nodes and Edges

Before we start mastering anything, it is imperative we understand what a graph is. A graph consists of a set of vertices and edges, while, each vertex and edge has a map or certain properties.
Picture of a graph

From now on we'll be assuming you have Apache AGE installed and configured correctly with postgreSQL. Start the postgres server with the following command
pg_ctl -D agedemo -l logfile start

In my case, I have created a database named agedemo and connected to it with the command:
psql agedemo

Now, I've created a graph called Halo based on the game as follows:

Image description

The load and SET lines are standard for setting up the configs for Apache AGE. The create_graph is a function in the ag_catalog and is used to create a graph and accepts the name of the graph you want to create as a parameter.

Another function we will be using will be the Cypher function used for constructing cypher queries.

Image description

Now with the SELECT * FROM cypher command we have created a vertice with name and title properties:

Image description

So Far, So Good!

Similarly, we have created an addtional two more for two more characters:

Image description

Image description

Alright now let's create a relationship between the two vertices. We will make Master Chief a "LOVER_OF" Cortana cause let's face it we all know that is what they really are. We will do it as follows:

Image description

And there you have it. Now for bonus points, if you have Apache AGE-Viewer installed then you can visualized what you have created as follows:

Image description

Top comments (0)