直接使用顶点V:
-- # 小朱25岁,出生在教师家庭并且有个姐姐小田,他现在奋斗在帝都。
CREATE VERTEX V SET name="小朱",sex="男",age="25";
CREATE VERTEX V SET name="小田",sex="女",age="27";
CREATE EDGE E FROM #9:0 TO #10:0 SET name="sister";
CREATE EDGE E FROM #10:0 TO #9:0 SET name="brother";
SELECT * FROM V WHERE name in ['小朱',"小田"];
image.png
image.png
image.png
-- # 小朱还有一个可爱的女盆友叫小刘
CREATE VERTEX V SET name="小刘",sex="女",age="23";
CREATE EDGE E FROM #9:0 TO #11:0 SET name="lover";
CREATE EDGE E FROM #11:0 TO #9:0 SET name="lover";
image.png
image.png
-- # 小朱目前工作在企业Google,他有一堆同事小马、小龚、小微…..
CREATE VERTEX V SET name="Google";
CREATE VERTEX V SET name="小马",sex="男",age="29",company="Google";
CREATE VERTEX V SET name="小龚",sex="男",age="28",company="Google";
CREATE VERTEX V SET name="小微",sex="女",age="24",company="Google";
UPDATE V SET company = 'Google' WHERE name='小朱'
CREATE EDGE E FROM (select from V where company='Google') TO (select from V where name ='Google') SET name="employee";
image.png
image.png
-- # 小朱目前跟不同同事合作完成了如下项目:PROJECT-1,PROJECT-2,PROJECT-3…..
CREATE VERTEX V SET name="PROJECT-1",type='JAVA',starttime='2016/01/01';
CREATE VERTEX V SET name="PROJECT-2",type='JAVA',starttime='2016/01/01';
CREATE VERTEX V SET name="PROJECT-3",type='JAVA',starttime='2016/01/01';
CREATE EDGE E FROM (select from V where name in ['小朱','小马','小微']) TO (select from v where name='PROJECT-1') SET name="work";
CREATE EDGE E FROM (select from V where name in ['小朱','小马','小微','小龚']) TO (select from v where name='PROJECT-2') SET name="work";
CREATE EDGE E FROM (select from V where name in ['小朱','小马','小龚']) TO (select from v where name='PROJECT-3') SET name="work";
image.png
image.png
NOTE:
所有点和边缘均继承祖先V、E对象,不能方便的通过语句进行筛选,不推荐直接创建V、E记录。
使用扩展的顶点和边:
CREATE CLASS Company EXTENDS V;
CREATE CLASS Project EXTENDS V;
CREATE CLASS Preson EXTENDS V;
CREATE CLASS Lover EXTENDS E;
CREATE CLASS Sister EXTENDS E;
CREATE CLASS Brother EXTENDS E;
CREATE CLASS Employee EXTENDS E;
CREATE CLASS Work EXTENDS E;
CREATE VERTEX Preson SET name="小朱",sex="男",age="25",company="Google";
CREATE VERTEX Preson SET name="小刘",sex="女",age="23";
CREATE VERTEX Preson SET name="小田",sex="女",age="27";
CREATE VERTEX Company SET name="Google";
CREATE VERTEX Preson SET name="小马",sex="男",age="29",company="Google";
CREATE VERTEX Preson SET name="小龚",sex="男",age="28",company="Google";
CREATE VERTEX Preson SET name="小微",sex="女",age="24",company="Google";
CREATE VERTEX Project SET name="PROJECT-1",type='JAVA',starttime='2016/01/01';
CREATE VERTEX Project SET name="PROJECT-2",type='JAVA',starttime='2016/01/01';
CREATE VERTEX Project SET name="PROJECT-3",type='JAVA',starttime='2016/01/01';
-- # 把以前的顶点移动到每个具体的类别
-- # MOVE VERTEX(SELECT FROM V WHERE name='Google') TO CLASS:Company;
-- #创建情侣关系
CREATE EDGE Lover FROM (select from Preson where name='小朱') TO (select from Preson where name='小刘');
CREATE EDGE Lover FROM (select from Preson where name='小刘') TO (select from Preson where name='小朱');
-- #创建姐弟关系
CREATE EDGE Sister FROM (select from Preson where name='小朱') TO (select from Preson where name='小田');
CREATE EDGE Brother FROM (select from Preson where name='小田') TO (select from Preson where name='小朱');
-- #创建雇佣关系
CREATE EDGE Employee FROM (select from Preson where company='Google') TO (select from Company where name ='Google');
-- #创建项目关系
CREATE EDGE Work FROM (select from Preson where name in ['小朱','小马','小微']) TO (select from Project where name='PROJECT-1');
CREATE EDGE Work FROM (select from Preson where name in ['小朱','小马','小微','小龚']) TO (select from Project where name='PROJECT-2');
CREATE EDGE Work FROM (select from Preson where name in ['小朱','小马','小龚']) TO (select from Project where name='PROJECT-3');
查看:
SELECT * FROM V;
图1 顶点&边的图
图二 完整的WEB UI
扩展阅读:
OrientDB 图计算框架
http://blog.csdn.net/zhufengyi/article/details/53037764
简介:
介绍了SQL命令,还提供了场景。
网友评论