Orientdb 简明教程

OrientDB - Create Edge

在 OrientDB 中, Edge 概念的作用是借助一些属性在顶点之间建立关系。边和顶点是图数据库的主要组成部分。它对边运用多态。边的基类是 E。在实现边时,如果源顶点或目标顶点缺失或不存在,则将回滚该事务。

In OrientDB, the concept Edge works like a relation between vertices with the help of some properties. Edges and vertices are the main components of a graph database. It applies polymorphism on Edges. The base class for an Edge is E. While implementing edges, if source or destination vertices are missing or don’t exist, then the transaction will be rollback.

以下语句是创建边命令的基本语法。

The following statement is the basic syntax of Create Edge Command.

CREATE EDGE <class> [CLUSTER <cluster>] FROM <rid>|(<query>)|[<rid>]* TO <rid>|(<query>)|[<rid>]*
     [SET <field> = <expression>[,]*]|CONTENT {<JSON>}
     [RETRY <retry> [WAIT <pauseBetweenRetriesInMs]] [BATCH <batch-size>]

以下是上文中选项的详细信息。

Following are the details about the options in the above syntax.

<class> − 定义边的类名。

<class> − Defines the class name for the edge.

<cluster> − 定义用于存储边的集群。

<cluster> − Defines the cluster in which you want to store the edge.

JSON − 提供要设置为记录的 JSON 内容。

JSON − Provides JSON content to set as the record.

RETRY − 定义在发生冲突时尝试的重试次数。

RETRY − Defines the number of retries to attempt in the event of conflict.

WAIT − 定义重试之间以毫秒为单位的延迟时间。

WAIT − Defines the time to delay between retries in milliseconds.

BATCH − 定义它是否将命令分解为较小的块以及批处理的大小。

BATCH − Defines whether it breaks the command down into smaller blocks and the size of the batches.

Example

执行以下查询,在两个顶点 #9:0 和 #14:0 之间创建一个边 E。

Execute the following query to create an edge E between two vertices #9:0 and #14:0.

orientdb> CREATE EDGE FROM #11:4 TO #13:2

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

Created edge '[e[#10:0][#9:0->#14:0]]' in 0.012000 sec(s)

执行以下查询,创建一个新的边类型和一个新类型的边。

Execute the following query to create a new edge type and an edge of new type.

orientdb> CREATE CLASS E1 EXTENDS E
orientdb> CREATE EDGE E1 FROM #10:3 TO #11:4

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

Created edge '[e[#10:1][#10:3->#11:4]]' in 0.011000 sec(s)