嬴图Node.js驱动提供一系列数据类,用于应用与图数据库的交互。所有数据类均支持getter方法获取属性和setter方法设置属性。
Node
Node
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
uuid |
string | / | 点_uuid |
id |
string | / | 点_id |
schema |
string | / | 点所属的Schema名称 |
values |
[key: string]: any | / | 点属性键值对 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("MATCH (n) RETURN n LIMIT 5",requestConfig);
const nodes = response.alias("n").asNodes();
console.log("ID of the first node:", nodes[0].id);
console.log("Name of the first node:", nodes[0].get("name"))
ID of the first node: ULTIPA800000000000004B
Name of the first node: Claire89
Edge
Edge
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
uuid |
string | / | 边_uuid |
fromUuid |
string | / | 边起点的_uuid |
toUuid |
string | / | 边终点的_uuid |
from |
string | / | 边起点的_id |
to |
string | / | 边终点的_id |
schema |
string | / | 边所属的Schema名称 |
values |
[key: string]: any | / | 边属性键值对 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("MATCH ()-[e]->() RETURN e LIMIT 3",requestConfig);
const edges = response.alias("e").asEdges();
for (const edge of edges) {
console.log(edge.values)
}
{toUuid: 13, uuid: 110, fromUuid: 7}
{toUuid: 1032, uuid: 1391, fromUuid: 7, timestamp: 1537331913, datetime: '2018-09-19 12:38:33'}
{toUuid: 1005, uuid: 1390, fromUuid: 7, timestamp: 1544118960, datetime: '2018-12-07 01:56:00'}
Path
Path
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
nodeUuids |
string[] | / | 路径中点的_uuid 列表 |
edgeUuids |
string[] | / | 路径中边的_uuid 列表 |
nodes |
Map<string, Node > |
{} |
路径中点的映射,其中键是点的_uuid ,值是相应的点 |
edges |
Map<string, Edge > |
{} |
路径中边的映射,其中键是边的_uuid ,值是相应的边 |
Path
对象支持的方法:
方法 |
返回值 |
描述 |
---|---|---|
length() |
number | 获取路径长度,即路径中的边数量 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("MATCH p = ()-[]-()-[]-() RETURN p LIMIT 3", requestConfig);
const graph = response.alias("p").asGraph();
console.log("Nodes in each returned path:")
const paths = graph.getPaths();
for (const path of paths) {
console.log(path.nodeUuids)
}
Nodes in each returned path:
['6196955286285058052', '7998395137233256457', '8214567919347040275']
['6196955286285058052', '7998395137233256457', '8214567919347040275']
['6196955286285058052', '7998395137233256457', '5764609722057490441']
Graph
Graph
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
paths |
Path [] |
[] |
返回的路径列表 |
nodes |
Map<string, Node > |
{} |
图中点的映射,其中键是点的_uuid ,值是相应的点 |
edges |
Map<string, Edge > |
{} |
图中边的映射,其中键是边的_uuid ,值是相应的边 |
Graph
对象支持的方法:
方法 |
参数 |
返回值 |
描述 |
---|---|---|---|
addNode() |
node: Node |
/ | 向nodes 中新增一个点 |
addEdge() |
edge: Edge |
/ | 向edges 中新增一条边 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("MATCH p = ()-[]-()-[]-() RETURN p LIMIT 3", requestConfig);
const graph = response.alias("p").asGraph();
console.log("Nodes in each returned path:")
const paths = graph.getPaths();
for (const path of paths) {
console.log(path.nodeUuids)
}
console.log("----------");
console.log("Nodes in the graph formed by all returned paths:");
console.log(graph.nodes.keys());
Nodes in each returned path:
['6196955286285058052', '7998395137233256457', '8214567919347040275']
['6196955286285058052', '7998395137233256457', '8214567919347040275']
['6196955286285058052', '7998395137233256457', '5764609722057490441']
----------
Nodes in the graph formed by all returned paths:
[Map Iterator]{'6196955286285058052', '7998395137233256457', '8214567919347040275', '5764609722057490441'}
GraphSet
GraphSet
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
string | / | 图ID |
name |
string | / | 图名称 |
totalNodes |
string | / | 图中点的总数 |
totalEdges |
string | / | 图中边的总数 |
shards |
string[] | [] |
用来存储图的Shard服务器的ID列表 |
partitionBy |
string | Crc32 |
用于图分片的哈希函数,包括Crc32 、Crc64WE 、Crc64XZ 和CityHash64 |
status |
string | / | 图状态,包括NORMAL 、LOADING_SNAPSHOT 、CREATING 、DROPPING 和SCALING |
description |
string | / | 图描述 |
slotNum |
number | 0 | 图分片使用的槽数量 |
const response = await conn.gql("SHOW GRAPH");
const graphs = response.alias("_graph").asGraphSets();
for (const graph of graphs) {
console.log(graph.name)
}
DFS_EG
cyber
netflow
Schema
Schema
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | Schema名称 |
dbType |
DBType |
/ | Schema类型,包括DBNODE 和DBEDGE |
properties |
Property [] |
/ | 与Schema关联的属性列表 |
description |
string | / | Schema描述 |
total |
string | 0 | 属于该Schema的点或边总数 |
id |
string | / | Schema ID |
stats |
SchemaStat [] |
/ | 一个SchemaStat 对象列表,每个SchemaStat 对象包含属性schema (Schema名称)、dbType (Schema类型)、fromSchema (起点Schema)、toSchema (终点Schema)以及count (点或边的数量) |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("SHOW NODE SCHEMA", requestConfig);
const schemas = response.alias("_nodeSchema").asSchemas();
for (const schema of schemas) {
console.log(schema.name)
}
default
account
celebrity
country
movie
Property
Property
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 属性名 |
type |
UltipaPropertyType |
/ | 属性值类型,包括INT32 、UINT32 、INT64 、UINT64 、FLOAT 、DOUBLE 、DECIMAL 、STRING 、TEXT 、DATETIME 、TIMESTAMP 、BLOB 、BOOL 、POINT 、LIST 、SET 、MAP 、NULL 、UUID 、ID 、FROM 、FROM_UUID 、TO 、TO_UUID 、IGNORE 和UNSET |
subType |
UltipaPropertyType [] |
/ | 如果type 为LIST 或SET ,设定其元素类型;列表内只能包括一个UltipaPropertyType ,且只能为INT32 、UINT32 、INT64 、UINT64 、FLOAT 、DOUBLE 、DECIMAL 、STRING 、TEXT 、DATETIME 或TIMESTAMP |
schema |
string | / | 属性关联的Schema名称 |
description |
string | / | 属性描述 |
lte |
boolean | / | 属性是否加载到引擎(LTE) |
read |
boolean | / | 属性是否可读 |
write |
boolean | / | 属性是否可写 |
encrypt |
string | / | 属性加密方法,包括AES128 、AES256 、RSA 和ECC |
decimalExtra |
DecimalExtra |
/ | DECIMAL 类型的精度(1到65)和标度(0到30) |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("SHOW NODE account PROPERTY", requestConfig);
const properties = response.alias("_nodeProperty").asProperties();
for (const property of properties) {
console.log(property.name)
}
title
profile
age
name
logo
Attr
Attr
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 返回的别名 |
values |
object[] | / | 返回值 |
propertyType |
UltipaPropertyType |
/ | 返回结果的类型 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("MATCH (n:account) RETURN n.name LIMIT 3");
const attr = response.alias("n.name").asAttr();
console.log("name:", attr.name);
console.log("values:", attr.values);
console.log("type:", attr.propertyType);
name: n.name
values: ['Velox', 'K03', 'Lunatique']
type: 7
Table
Table
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 表名称 |
headers |
Header [] |
/ | 表头 |
rows |
any[][] | / | 表中的行 |
Methods on a Table
object:
方法 |
返回值 |
描述 |
---|---|---|
toKV() |
any[] | 将表中的所有行转换成键值对对象组成的数组 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql(
"MATCH (n:account) RETURN table(n._id, n.name) LIMIT 3",
requestConfig
);
const table = response.get(0).asTable();
console.log("Header:");
for (const header of table.getHeaders()) {
console.log(header.propertyName, " - ", header.propertyType);
}
console.log("First Row:");
const rows = table.toKV();
if (rows.length != 0) {
console.log(rows[0]);
}
Header:
n._id - 7
n.name - 7
First Row:
{'n._id': 'ULTIPA800000000000003B', 'n.name': 'Velox'}
HDCGraph
HDCGraph
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | HDC图名称 |
graphName |
string | / | HDC图的源图名称 |
status |
string | / | HDC图状态 |
stats |
string | / | HDC图的统计信息 |
isDefault |
string | / | 是否为源图的默认HDC图 |
hdcServerName |
string | / | 托管HDC图的HDC服务器名称 |
hdcServerStatus |
string | / | 托管HDC图的HDC服务器状态 |
config |
string | / | HDC图的配置 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.uql("hdc.graph.show()", requestConfig);
const hdcGraphs = response.alias("_hdcGraphList").asHDCGraphs();
for (const hdcGraph of hdcGraphs) {
console.log(hdcGraph.name, "on", hdcGraph.hdcServerName);
}
miniCircle_hdc_graph on hdc-server-1
miniCircle_hdc_graph2 on hdc-server-2
Algo
Algo
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 算法名称 |
type |
string | / | 算法类型 |
version |
string | / | 算法版本 |
params |
AlgoParam [] |
/ | 算法参数,每个AlgoParam 有属性name 和desc |
writeSupportType |
string | / | 算法支持的回写类型 |
canRollback |
string | / | 算法版本是否可回退 |
configContext |
string | / | 算法配置文件内容 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.uql("show().hdc('hdc-server-1')");
const algos = response.alias("_algoList").asAlgos();
for (const algo of algos) {
if (algo.type == "algo") {
console.log(
`${algo.name} supports writeback types: ${algo.writeSupportType}`
);
}
}
fastRP supports writeback types: DB,FILE
struc2vec supports writeback types: DB,FILE
Projection
Projection
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 映射名称 |
graphName |
string | / | 映射的源图名称 |
status |
string | / | 映射状态 |
stats |
string | / | 映射的统计信息 |
config |
string | / | 映射的配置 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.uql("show().projection()", requestConfig);
const projections = response.alias("_projectionList").asProjections();
for (const projection of projections) {
console.log(projection.name)
}
miniCircle_projection_1
Index
Index
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
string | / | 索引ID |
name |
string | / | 索引名称 |
properties |
string | / | 索引关联的属性 |
schema |
string | / | 索引关联的Schema |
status |
string | / | 索引状态 |
size |
string | / | 索引大小(单位:字节) |
dbType |
DBType |
/ | 索引类型,包括DBNODE 和DBEDGE |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("SHOW NODE INDEX", requestConfig);
const indexList = response.alias("_nodeIndex").asIndexes();
for (const index of indexList) {
console.log(index.schema, "-", index.properties)
}
account - gender(6)
account - year
Privilege
Privilege
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 权限名称 |
level |
PrivilegeLevel |
/ | 权限级别,包括GraphLevel 和SystemLevel |
const response = await conn.uql("show().privilege()");
const privileges = response.alias("_privilege").asPrivileges();
const graphPrivilegeNames = privileges
.filter((p) => p.level === PrivilegeLevel.GraphLevel)
.map((p) => p.name)
.join(", ");
console.log("Graph privileges: " + graphPrivilegeNames);
const systemPrivilegeNames = privileges
.filter((p) => p.level === PrivilegeLevel.SystemLevel)
.map((p) => p.name)
.join(", ");
console.log("System privileges: " + systemPrivilegeNames);
Graph privileges: READ, INSERT, UPSERT, UPDATE, DELETE, CREATE_SCHEMA, DROP_SCHEMA, ALTER_SCHEMA, SHOW_SCHEMA, RELOAD_SCHEMA, CREATE_PROPERTY, DROP_PROPERTY, ALTER_PROPERTY, SHOW_PROPERTY, CREATE_FULLTEXT, DROP_FULLTEXT, SHOW_FULLTEXT, CREATE_INDEX, DROP_INDEX, SHOW_INDEX, LTE, UFE, CLEAR_JOB, STOP_JOB, SHOW_JOB, ALGO, CREATE_PROJECT, SHOW_PROJECT, DROP_PROJECT, CREATE_HDC_GRAPH, SHOW_HDC_GRAPH, DROP_HDC_GRAPH, COMPACT_HDC_GRAPH, SHOW_VECTOR_INDEX, CREATE_VECTOR_INDEX, DROP_VECTOR_INDEX, SHOW_CONSTRAINT, CREATE_CONSTRAINT, DROP_CONSTRAINT
System privileges: TRUNCATE, COMPACT, CREATE_GRAPH, SHOW_GRAPH, DROP_GRAPH, ALTER_GRAPH, TOP, KILL, STAT, SHOW_POLICY, CREATE_POLICY, DROP_POLICY, ALTER_POLICY, SHOW_USER, CREATE_USER, DROP_USER, ALTER_USER, SHOW_PRIVILEGE, SHOW_META, SHOW_SHARD, ADD_SHARD, DELETE_SHARD, REPLACE_SHARD, SHOW_HDC_SERVER, ADD_HDC_SERVER, DELETE_HDC_SERVER, LICENSE_UPDATE, LICENSE_DUMP, GRANT, REVOKE, SHOW_BACKUP, CREATE_BACKUP, SHOW_VECTOR_SERVER, ADD_VECTOR_SERVER, DELETE_VECTOR_SERVER
Policy
Policy
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
name |
string | / | 策略名称 |
systemPrivileges |
string[] | / | 策略中包含的系统权限 |
graphPrivileges |
Map<string, string[]> | / | 策略中包含的图集权限;在映射中,键是图集名称,值是相应的图集权限 |
propertyPrivileges |
PropertyPrivilege |
/ | 策略中包含的属性权限;PropertyPrivilege 有node 和edge 两个属性,都是PropertyPrivilegeElement 对象 |
policies |
string[] | / | 策略中包含的其他策略 |
PropertyPrivilegeElement
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
read |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
write |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
deny |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
const response = await conn.uql("show().policy('Tester')");
const policy = response.alias("_policy").asPolicies();
console.log("Graph privileges: ", policy[0].graphPrivileges);
console.log("System privileges: ", policy[0].systemPrivileges);
console.log("Property privileges:");
console.log("- Node (Read): ", policy[0].propertyPrivileges.node.read);
console.log("- Node (Write): ", policy[0].propertyPrivileges.node.write);
console.log("- Node (Deny): ", policy[0].propertyPrivileges.node.deny);
console.log("- Edge (Read): ", policy[0].propertyPrivileges.edge.read);
console.log("- Edge (Write): ", policy[0].propertyPrivileges.edge.write);
console.log("- Edge (Deny): ", policy[0].propertyPrivileges.edge.deny);
console.log("Policies: ", policy[0].policies)
Graph Privileges: Map(3) {'amz' => ['ALGO', 'INSERT', 'DELETE', 'UPSERT'], 'StoryGraph' => ['UPDATE', 'READ']}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
User
User
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
username |
string | / | 用户名 |
password |
string | / | 密码 |
createdTime |
Date |
/ | 用户创建时间 |
systemPrivileges |
string[] | / | 授予用户的系统权限 |
graphPrivileges |
Map<string, string[]> | / | 授予用户的图集权限;在映射中,键是图集名称,值是相应的图集权限 |
propertyPrivileges |
PropertyPrivilege |
/ | 授予用户的属性权限;PropertyPrivilege 有node 和edge 两个属性,都是PropertyPrivilegeElement 对象 |
policies |
string[] | / | 授予用户的策略 |
PropertyPrivilegeElement
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
read |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
write |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
deny |
string[][] | / | 一个由数组组成的数组;每个内部数组包含三个字符串,分别表示图、Schema和属性 |
const response = await conn.uql("show().user('johndoe')");
const user = response.alias("_user").asUsers();
console.log("Created Time: ", user[0].createdTime);
console.log("Graph privileges: ", user[0].graphPrivileges);
console.log("System privileges: ", user[0].systemPrivileges);
console.log("Property privileges:");
console.log("- Node (Read): ", user[0].propertyPrivileges.node.read);
console.log("- Node (Write): ", user[0].propertyPrivileges.node.write);
console.log("- Node (Deny): ", user[0].propertyPrivileges.node.deny);
console.log("- Edge (Read): ", user[0].propertyPrivileges.edge.read);
console.log("- Edge (Write): ", user[0].propertyPrivileges.edge.write);
console.log("- Edge (Deny): ", user[0].propertyPrivileges.edge.deny);
console.log("Policies: ", user[0].policies);
Created Time: 2025-04-02 11:08:38
Graph Privileges: Map(2){'amz'=> ['ALGO', 'INSERT', 'DELETE', 'UPSERT'], 'StoryGraph'=> ['UPDATE', 'READ']}
System Privileges: ['TRUNCATE', 'KILL', 'TOP']
Property Privileges:
- Node (Read): [['*', '*', '*']]
- Node (Write): []
- Node (Deny): []
- Edge (Read): []
- Edge (Write): [['amz', '*', '*'], ['alimama', '*', '*']]
- Edge (Deny): [['miniCircle', 'review', 'value, timestamp']]
Policies: ['sales', 'manager']
Process
Process
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
processId |
string | / | 进程ID |
processQuery |
string | / | 进程执行的语句 |
status |
string | / | 进程状态 |
duration |
string | / | 任务的运行时长(单位:秒) |
const response = await conn.uql("top()");
const processes = response.alias("_top").asProcesses();
for (const process of processes) {
console.log(process.processId);
}
1049435
Job
Job
对象包含以下属性:
属性 |
类型 |
默认 |
描述 |
---|---|---|---|
id |
string | / | 作业ID |
graphName |
string | / | 作业执行所在的图名称 |
query |
string | / | 作业执行的语句 |
type |
string | / | 作业类型 |
errNsg |
string | / | 作业错误信息 |
result |
Map<any, any> | / | 作业结果 |
startTime |
string | / | 作业开始时间 |
endTime |
string | / | 作业结束时间 |
status |
string | / | 作业状态 |
progress |
string | / | 作业的进度更新,例如提示回写操作已开始 |
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
const response = await conn.gql("SHOW JOB", requestConfig);
const jobs = response.alias("_job").asJobs();
const falid_jobs = jobs.filter((job) => job.status === "FAILED");
if (falid_jobs.length > 0) {
for (const job of falid_jobs) {
console.log(job.id, "_", job.errMsg, "-", job.type);
}
}
51 - Fulltext name already exists. - CREATE_FULLTEXT
42 - Fulltext name already exists. - CREATE_FULLTEXT
26 - [engine] uuids should be unsigned integer - HDC_ALGO
26_1 - - HDC_ALGO
17 - [engine] all failed, because some nodes do not exist in db - HDC_ALGO
17_1 - - HDC_ALGO