<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Udaya Ganesh</title>
    <description>The latest articles on DEV Community by Udaya Ganesh (@udaiganny67).</description>
    <link>https://dev.to/udaiganny67</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1022018%2F5bae2ce4-5177-4b43-8d5e-ab04462e1fb7.png</url>
      <title>DEV Community: Udaya Ganesh</title>
      <link>https://dev.to/udaiganny67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/udaiganny67"/>
    <language>en</language>
    <item>
      <title>Apache AGE: Transform Relational Database to Graph Database</title>
      <dc:creator>Udaya Ganesh</dc:creator>
      <pubDate>Thu, 21 Sep 2023 19:21:33 +0000</pubDate>
      <link>https://dev.to/udaiganny67/apache-age-transform-relational-database-to-graph-database-1db</link>
      <guid>https://dev.to/udaiganny67/apache-age-transform-relational-database-to-graph-database-1db</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Understanding the relationship between the different data members is very important for better working of data and the applications. From the very beginning data has been an important part of computer applications. Relational databases like MySQL and PostgreSQL can store the data very efficiently. But as the data grows and they have some complex relations between the data elements. It’s very important to understand the relations between data. Here comes the graph database. Unlike a relational database which uses tables or documents to store data, a graph database uses graph concepts to store and represent data effectively.&lt;/p&gt;

&lt;p&gt;Figure 1                    A relational Database&lt;/p&gt;

&lt;h2&gt;
  
  
  Graph Database
&lt;/h2&gt;

&lt;p&gt;Graph database organizes or store data in the form of vertex and edges. It stores the relationship between data as an edge and the data as a node or vertex. So, it’s very helpful to understand the complex relations between the data.&lt;/p&gt;

&lt;p&gt;Figure 2         A Graph database&lt;br&gt;
Understanding the relation between the data is much easier with graph databases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Apache AGE
&lt;/h2&gt;

&lt;p&gt;Apache AGE is a powerful PostgreSQL extension which is used to convert relational databases into graph databases. AGE is an acronym for “A Graph Extension”. It combines both the advantages of relational databases using PostgreSQL with the Graph database. Apache AGE’s main goal or functionality is to provide graph data processing and analytics capabilities to all relational databases. With the help of this extension users can have access to graph query modeling within their existing relational databases. With the help of this extension users can read and write graph data in nodes and edges. And they can also use various graph algorithms to analyze data. Some of its main features are: &lt;br&gt;
• Hybrid queries (OpenCypher and SLQ),&lt;br&gt;
• Fast Graph Query processing &lt;br&gt;
• Graph Visualization and Analytics &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Apache AGE
&lt;/h2&gt;

&lt;p&gt;It gives user to have the ability of both relational and graph data models within the same database system. As it is an extension of PostgreSQL which is a relational database. It’s an opensource project which is being managed by Apache Software Foundation. So, users can take advantage of its open source also.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use AGE
&lt;/h2&gt;

&lt;p&gt;You can check their official documentation to know more about AGE. Once you have installed the extension on your system you can easily use it and convert your already existing relational data into a graph database. You can easily select your platform and incorporate the relevant SDK into your code because it has some built-in drivers for Go, java, Nodejs and Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Convert relation to Graph database
&lt;/h2&gt;

&lt;p&gt;There are currently two ways to import data into a graph in AGE via sql. These are supported in AGE version 0.4.0 release. &lt;/p&gt;

&lt;h3&gt;
  
  
  Method 1
&lt;/h3&gt;

&lt;p&gt;So, you would need to format the query as &lt;/p&gt;

&lt;p&gt;PREPARE create_person AS&lt;br&gt;
SELECT *&lt;br&gt;
FROM cypher('graph_name', $$&lt;br&gt;
CREATE (:Person {name: $name, title: $title})&lt;br&gt;
$$, $1) as (n agtype);&lt;/p&gt;

&lt;p&gt;Then to run the basic example you would do&lt;/p&gt;

&lt;p&gt;EXECUTE create_person('{"name": "Andres", "title": "Developer"}');&lt;/p&gt;

&lt;h3&gt;
  
  
  Method 2
&lt;/h3&gt;

&lt;p&gt;You could make a pl/pgsql function that takes in your argument name and title and creates a node, such as&lt;/p&gt;

&lt;p&gt;CREATE OR REPLACE FUNCTION public.create_person(name text, title text)&lt;br&gt;
RETURNS void&lt;br&gt;
LANGUAGE plpgsql&lt;br&gt;
VOLATILE&lt;br&gt;
AS $BODY$&lt;br&gt;
BEGIN&lt;br&gt;
    load 'age';&lt;br&gt;
    SET search_path TO ag_catalog;&lt;br&gt;
    EXECUTE format('SELECT * FROM cypher(''graph_name'', $$CREATE (:Person {name: %s, title: %s})$$) AS (a agtype);', quote_ident(name), quote_ident(title));&lt;br&gt;
END&lt;br&gt;
$BODY$;&lt;/p&gt;

&lt;p&gt;Then you could call the function like:&lt;/p&gt;

&lt;p&gt;SELECT public.create_person(sql_person.name, sql_person.title) &lt;br&gt;
FROM sql_schema.Person AS sql_person;&lt;/p&gt;

&lt;p&gt;In this way by calling your pgsql function that you created you can convert your relational database into graph database. &lt;br&gt;
If you want to further explore this conversion part you can check this issue from their official site. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Apache AGE is a big development. It expands the usage of data and database as both of relation as well as Graph modeling along with ensuring the complex relations are represented efficiently. As an extension of PostgreSQL (used by Apple, Spotify and NASA) AGE supports all the functionality and features of PostgreSQL while also offering a graph model to boot.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/apache/age"&gt;https://github.com/apache/age&lt;/a&gt; &lt;br&gt;
&lt;a href="https://neo4j.com/developer/graph-database/"&gt;https://neo4j.com/developer/graph-database/&lt;/a&gt; &lt;br&gt;
&lt;a href="https://age.apache.org/"&gt;https://age.apache.org/&lt;/a&gt; &lt;/p&gt;

</description>
      <category>apacheag</category>
    </item>
  </channel>
</rss>
