Graph 由 vertex 和 edge 组成。vertex 可翻译成顶点,edge 翻译为边,顶点与边组成图形(Graph)。

边作为文档(document)存储在边集合(edge collection)中,边与普通文档相比,特殊点在于有两个特殊属性:_from 和 _to 。顶点可以是文档的集合,也可以是边集合,即边(edge)可以作为顶点(vertex)。

除了可以使用标准的集合方法进行访问之外,图形模块在其上添加了一个附加层,提供以下保证:

  • 所有修改都被执行
  • 如果删除一个顶点,与此直接相关的所有边都将被删除
  • 如果插入边,则检查边是否与边定义(edge definition)相匹配。边集合将只包含有效的边

注:如果使用图形模块或 AQL 之外的方式访问集合的话,以上保证将丢失。(试了下,匿名图,改保证丢失)

API

var graph_module = require("@arangodb/general-graph")

相关 API:部分 API 说明:

// 创建并返回一个图形
graph_module._create(graphName [, edgeDefinitions, orphanCollections])

// 返回一个relation:
// {
//   collection: relationName,
//   from: stringToArray(fromVertexCollections),
//   to: stringToArray(toVertexCollections)
// }
graph_module._relation(relationName, fromVertexCollections, toVertexCollections)

// 创建并返回一个边定义
graph_module._edgeDefinitions(relation1, relation2, ..., relationN)
// 为边定义添加额外的边,返回修改后的边定义
graph_module._extendEdgeDefinitions(edgeDefinitions, relation1, relation2, ..., relationN)


// 列出所有图形
graph_module._list()

// 获取一个图形
graph_module._graph(graphName)

graph_module._drop(graphName [, dropCollections])
var graph = graph_module._create("myGraph")

相关 API:部分 API 说明:

// 为图形添加顶点集合
// createCollection 是否创建集合
graph._addVertexCollection(vertexCollectionName [, createCollection])

// 修改一个边定义
graph._editEdgeDefinition(edgeDefinition)

// 删除一个边定义
graph_module._deleteEdgeDefinition(edgeCollectionName, dropCollection)

results matching ""

    No results matching ""