zoukankan      html  css  js  c++  java
  • 图数据库orientDB(1-2)例子

    http://gog.orientdb.com/index.html#/infotab

    小朱25岁,出生在教师家庭并且有个姐姐小田,他现在奋斗在帝都。 
    那么SQL是这样滴!!!

     

    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="sisiter";

    CREATE EDGE E FROM #10:0 TO #9:0 SET name="brother";

    Select  from V where name in ['小朱',"小田"];

    * select 在 Graph 页面查询会自动渲染出关系结果

    小朱还有一个可爱的女盆友叫小刘

    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";

     

     

    小朱目前工作在企业ABC,他有一堆同事小马、小龚、小微…..

    CREATE VERTEX V SET name="ABC";

    CREATE VERTEX V SET name="小马",sex="男",age="29",company="ABC";

    CREATE VERTEX V SET name="小龚",sex="男",age="28",company="ABC";

    CREATE VERTEX V SET name="小微",sex="女",age="24",company="ABC";

    UPDATE V SET company = 'ABC' WHERE name='小朱'

    CREATE EDGE E FROM (select from V where company='ABC') TO (select from V where name ='ABC') SET name="employee";

     

    小朱目前跟不同同事合作完成了如下项目: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";

     

     

    以上描述中,所有点和边缘均继承祖先V、E对象,不能方便的通过语句进行筛选,不推荐直接创建V、E记录。

    改造以上实例,用不同的关系对象表示

    上图出现了两种对象(公司,人,项目)……划分规则,看心情 
    有5类关系(情侣,姐,弟,雇员,合作) 
    莫名其妙有了V{Company,Preson,Project},E{Lover,sisiter,brother,employee,work}

    CREATE CLASS Company EXTENDS V;

    CREATE CLASS Project EXTENDS V;

    CREATE CLASS Preson EXTENDS V;

    CREATE CLASS Lover EXTENDS E;

    CREATE CLASS Sisiter 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="Lianjia";

    CREATE VERTEX Preson SET name="小刘",sex="女",age="23";

    CREATE VERTEX Preson SET name="小田",sex="女",age="27";

    CREATE VERTEX Company SET name="Lianjia";

    CREATE VERTEX Preson SET name="小马",sex="男",age="29",company="Lianjia";

    CREATE VERTEX Preson SET name="小龚",sex="男",age="28",company="Lianjia";

    CREATE VERTEX Preson SET name="小微",sex="女",age="24",company="Lianjia";

    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='ABC') 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 Sisiter 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='Lianjia') TO (select from Company where name ='Lianjia');

     

    #创建项目关系

    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');

     
  • 相关阅读:
    读书笔记-《编写可读代码的艺术》一
    maven报错Error:(4, 35) java:程序包org.springframework.context不存在
    AutoCAD.Net/C#.Net QQ群:193522571 当需要把wipeout加入到block中时,必须把wipeout放在objectidcollection中的第一位
    AutoCAD.Net/C#.Net QQ群:193522571 绘制椭圆及椭圆弧
    AutoCAD.Net/C#.Net QQ群:193522571 Nested Select后,如果有上一级图元则ResultNestedContainer不为Null,从小到大,从父亲到爷爷
    AutoCAD.Net/C#.Net QQ群:193522571 标注对象Dimension中的DimensionText和Measurement的区别
    AutoCAD.Net/C#.Net QQ群:193522571 同一套窗体代码,同时用在Winform、PvBox和PvTools中
    AutoCAD.Net/C#.Net QQ群:193522571 当用户使用的不是默认的WCS坐标系时,打印程序容易打成空白,因为点没有转换
    AutoCAD.Net/C#.Net QQ群:193522571 ComBobox绑定Datatable并去除重复!
    AutoCAD.Net/C#.Net QQ群:193522571 字段包含于一个字符串的SQL
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6672778.html
Copyright © 2011-2022 走看看