In the previous blog posts, we have seen the usage of SQL API and Table API to work with our database in CosmosDB. In this article, we look at the usage of Gremlin API to work with the Graph databases.
These different APIs that we work with actually act as containers for our data in the databases. So basically, Gremlin API is a container for graphs in the graph databases, same is with the tables in a Table API and documents in a SQL API.
So, as we have worked with entities and relationships, in Graph databases these terms are replaced by vertex and edges. So basically, a vertex is some entity and the edge is a relationship that is one-way between two vertices.
We can say that to learn what are graph databases, this knowledge of vertex and edges is the building block. And just like we store the key-value pair attributes for the SQL or the Table API, we can store any number of attributes with the vertex and edges.
Working with Vertices and Edges
Let us see how to work with the vertices that is the entities and the edges which are the relationships between those vertices. So, to create, read, update, and delete the vertices and edges, we work with GraphSON and Gremlin.
What are GraphSON and Gremlin? These conventions come from the Apache Open Source project called TinkerPop and used to work with vertices and edges in graph databases.
GraphSON is used for describing vertices and edges in a JSON format. And Gremlin is a language used to create the vertices and edges and to then query the graphs and their relationships.
One good thing with the graph databases is that they are used for handling complex relationships and are better than relational databases to handle complex entity-relationships. This is because, in a graph database, relationships themselves are defined as objects.