DEV Community

Cover image for University Management System in Apache AGE - Part-3
Muhammad Muneeb Ur Rehman
Muhammad Muneeb Ur Rehman

Posted on • Edited on

University Management System in Apache AGE - Part-3

Now we will see the relations (edges) in our University Management System with the help of some dummy data insertion and in the end, we will see how it will look like in Apache AGE Viewer.

Enrolled_In relation:
The students get enrolled in different courses. Here is an example with some dummy data where I have created five enrollment relations between students and courses.

Enrollment-1:
SELECT *
FROM cypher('university', $$
MATCH (s:student), (c:course)
WHERE s.name = 'std1' AND c.name = 'Database' CREATE (s)-[e:enrolled_in]->(c)
RETURN e
$$) as (e agtype);

Enrollment-2:
SELECT *
FROM cypher('university', $$
MATCH (s:student), (c:course)
WHERE s.name = 'std2' AND c.name = 'Database' CREATE (s)-[e:enrolled_in]->(c)
RETURN e
$$) as (e agtype);

Enrollment-3:
SELECT *
FROM cypher('university', $$
MATCH (s:student), (c:course)
WHERE s.name = 'std3' AND c.name = 'Programming' CREATE (s)-[e:enrolled_in]->(c)
RETURN e
$$) as (e agtype);

Enrollment-4:
SELECT *
FROM cypher('university', $$
MATCH (s:student), (c:course)
WHERE s.name = 'std4' AND c.name = 'Programming' CREATE (s)-[e:enrolled_in]->(c)
RETURN e
$$) as (e agtype);

Enrollment-5:
SELECT *
FROM cypher('university', $$
MATCH (s:student), (c:course)
WHERE s.name = 'std5' AND c.name = 'Programming' CREATE (s)-[e:enrolled_in]->(c)
RETURN e
$$) as (e agtype);

Taught_By Relation:
The courses are taught by different teachers. Here I have created two taught by relations between courses and teachers with dummy data:

Taught_By Relation-1:
SELECT *
FROM cypher('university', $$
MATCH (c:course), (t:teacher)
WHERE c.name = 'Programming' AND t.name = 'Muneeb'
CREATE (c)-[e:taught_by]->(t)
RETURN e
$$) as (e agtype);

Taught_By Relation-2:
SELECT *
FROM cypher('university', $$
MATCH (c:course), (t:teacher)
WHERE c.name = 'Programming' AND t.name = 'Muneeb'
CREATE (c)-[e:taught_by]->(t)
RETURN e
$$) as (e agtype);

Offered_By Relation:
The couses are offered by different departments. Here I have created two offered by relations between courses and department with dummy data:

Offered_By Relation-1:
SELECT *
FROM cypher('university', $$
MATCH (c:course), (d:Department)
WHERE c.name = 'Database' AND d.name = 'Computer Science'
CREATE (c)-[e:offered_by]->(d)
RETURN e
$$) as (e agtype);

Offered_By Relation-2:
SELECT *
FROM cypher('university', $$
MATCH (c:course), (d:Department)
WHERE c.name = 'Programming' AND d.name = 'Computer Science' CREATE (c)-[e:offered_by]->(d)
RETURN e
$$) as (e agtype);

Affiliated_With Raltion-1:
Every teacher is affiliated with any Department. Here I have created two affiliated with relations between teachers and department with some dummy data:

Affiliated_With Relation-1:
SELECT *
FROM cypher('university', $$
MATCH (t:teacher), (d:Department)
WHERE t.name = 'Muneeb' AND d.name = 'Computer Science'
CREATE (t)-[e:affiliated_with]->(d)
RETURN e
$$) as (e agtype);

Affliated_With Raltion-2:
SELECT *
FROM cypher('university', $$
MATCH (t:teacher), (d:Department)
WHERE t.name = 'Micheal' AND d.name = 'Computer Science' CREATE (t)-[e:affliated_with]->(d)
RETURN e
$$) as (e agtype);

University Management System in Age Viewer

For more details visit: https://age.apache.org/overview/

AGE Github Link: https://github.com/apache/age

AGE Viewer Github Link: https://github.com/apache/age-viewer

Top comments (0)