UltipaDocs
Try Playground
  • Introduction
  • RESTful API
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Node.js

Types Mapping Ultipa and Node.js

Mapping Methods

The get() or alias() method of the Response class returns a DataItem, which embeds the query result. You should use the as<Type>() method of DataItem to cast the result to the appropriate driver type.

TypeScript
let requestConfig = <RequestType.RequestConfig>{
  useMaster: true,
  graphSetName: "miniCircle",
};

let resp = await conn.uql(
  "find().nodes() as n return n{*} limit 5",
  requestConfig
);

console.log(resp.data?.get(0).asNodes());

The result n coming from the database contains five nodes, each of the NODE type. The asNodes() method converts them as a list of Node objects.

Type mapping methods available on DataItem:

UQL TypeUQL AliasMethodDriver Type
Description
NODEAnyasNodes()Node[]Maps NODE-type DataItem to a list of Node objects.
EDGEAnyasEdges()Edge[]Maps EDGE-type DataItem to a list of Edge objects.
PATHAnyasPaths()Path[]Maps PATH-type DataItem to a list of Path objects.
GRAPHAnyasGraph()GraphMaps GRAPH-type DataItem to a Graph object.
TABLE_graphasGraphInfos()GraphSet[]Maps DataItem with the alias _graph to a list of GraphSet objects.
TABLE_nodeSchema, _edgeSchemaasSchemas()Schema[]Maps DataItem with the alias _nodeSchema or _edgeSchema to a list of Schema objects.
TABLE_nodeProperty, _edgePropertyasProperties()Property[]Maps DataItem with the alias _nodeProperty or _edgeProperty to a list of Property objects.
TABLE_algoListasAlgos()Algo[]Maps DataItem with the alias _algoList to a list of Algo objects.
TABLE_extaListasExtas()Exta[]Maps DataItem with the alias _extaList to a list of Exta objects.
TABLE_nodeIndex, _edgeIndex, _nodeFulltext, _edgeFulltext/Index[]Maps DataItem with the alias _nodeIndex, _edgeIndex, _nodeFulltext or _edgeFulltext to a list of Index objects.
TABLE_privilege/PriviliegeMaps DataItem with the alias _privilege to a Priviliege object.
TABLE_policy/Policy[]Maps DataItem with the alias _policy to a list of Policy objects.
TABLE_user/User[]Maps DataItem with the alias _user to a list of User objects.
TABLE_statistic/StatsMaps DataItem with the alias _statistic to a Stats object.
TABLE_top/Process[]Maps DataItem with the alias _top to a list of Process objects.
TABLE_taskasTasks()Task[]Maps DataItem with the alias _task to a list of Task objects.
TABLEAnyasTable()TableMaps TABLE-type DataItem to a Table object.
ATTRAnyasAttr()AttrMaps ATTR-type DataItem to a Attr object.

Driver Types

NOTE

Objects of all driver types support getter methods to retrieve the value of a field and setter methods to set the value of a field, even if they are not explicitly listed below.

Node

A Node object has the following fields:

FieldType
Description
uuidstringNode UUID
idstringNode ID
schemastringNode Schema
valuesobjectNode custom properties

Methods on a Node object:

Method
Return
Description
get("<propertyName>")ObjectGet value of the given custom property of the node.
set("<propertyName>", <propertyValue>Set value for the given custom property of the node; or add a key-value pair to the values of the node if the given <propertyName> does not exist.
TypeScript
let resp = await conn.uql(
  "find().nodes() as n return n{*} limit 5",
  requestConfig
);
let nodeList = resp.data?.alias("n").asNodes();

console.log("ID of the 1st node:", nodeList[0].getID());
console.log("Name of the 1st node:", nodeList[0].get("name"));
Output
ID of the 1st node: ULTIPA8000000000000001
Name of the 1st node: Titanic

Edge

An Edge object has the following fields:

FieldType
Description
schemastringEdge Schema
fromstringStart node ID of the edge
tostringEnd node ID of the edge
uuidstringEdge UUID
from_uuidstringStart node UUID of the edge
to_uuidstringEnd node UUID of the edge
valuesobjectEdge custom properties

Methods on an Edge object:

Method
Return
Description
get("<propertyName>")ObjectGet value of the given custom property of the edge.
set("<propertyName>", <propertyValue>Set value for the given custom property of the edge; or add a key-value pair to the values of the edge if the given <propertyName> does not exist.
TypeScript
let resp = await conn.uql(
  "find().edges() as e return e{*} limit 5",
  requestConfig
);
let edgeList = resp.data?.alias("e").asEdges();

console.log("Values of the 1st edge", edgeList[0].getValues());
Output
Values of the 1st edge {
  datetime: '2019-01-06 02:57:57',
  timestamp: 1546714677,
  targetPost: '703'
}

Path

A Path object has the following fields:

Field
Type
Description
nodesNode[]Node list of the path
edgesEdge[]Edge list of the path
lengthnumberLength of the path, namely the number of edges in the path
TypeScript
let resp = await conn.uql(
  "n().e()[:2].n() as paths return paths{*} limit 5",
  requestConfig
);
let pathList = resp.data?.alias("paths").asPaths();

console.log("Length of the 1st path:", pathList[0].length);
console.log("Edge list of the 1st path:", pathList[0].getEdges());
console.log(
  "Information of the 2nd node in the 1st path:",
  pathList[0].getNodes()[1]
);
Output
Length of the 1st path: 2
Edge list of the 1st path: [
  Edge {
    from: 'ULTIPA800000000000001B',
    to: 'ULTIPA8000000000000001',
    uuid: '7',
    from_uuid: '27',
    to_uuid: '1',
    schema: 'follow',
    values: {}
  },
  Edge {
    from: 'ULTIPA8000000000000021',
    to: 'ULTIPA800000000000001B',
    uuid: '99',
    from_uuid: '33',
    to_uuid: '27',
    schema: 'follow',
    values: {}
  }
]
Information of the 2nd node in the 1st path: Node {
  id: 'ULTIPA800000000000001B',
  uuid: '27',
  schema: 'account',
  values: {
    year: 1988,
    industry: 'Transportation',
    double: '3.72'
  }
}

Graph

A Graph object has the following fields:

Field
Type
Description
nodesNode[]Node list of the path
edgesEdge[]Edge list of the path
nodeSchemasmap<string, schema>Map of all node schemas of the path
edgeSchemasmap<string, schema>Map of all edge schemas of the path
TypeScript
let resp = await conn.uql(
  "n(as n1).re(as e).n(as n2).limit(3) with toGraph(collect(n1), collect(n2), collect(e)) as graph return graph",
  requestConfig
);
let graphList = resp.data?.alias("graph").asGraph();

let nodeList = graphList.getNodes();
let edgeList = graphList.getEdges();
console.log(
  "Node IDs:",
  nodeList.map((node) => node.getID())
);
console.log(
  "Edge UUIDs:",
  edgeList.map((edge) => edge.getUUID())
);
Output
Node IDs: [
  'ULTIPA8000000000000017',
  'ULTIPA8000000000000001',
  'ULTIPA800000000000001B',
  'ULTIPA8000000000000061'
]
Edge UUIDs: [ '43', '1576', '29' ]

GraphSet

A GraphSet object has the following fields:

Field
Type
Description
idstringGraphset ID
namestringGraphset name
descriptionstringGraphset description
totalNodesstringTotal number of nodes in the graphset
totalEdgesstringTotal number of edges in the graphset
statusstringGraphset status (MOUNTED, MOUNTING, or UNMOUNTED)
TypeScript
let resp = await conn.uql("show().graph()");
let graphList = resp.data?.alias("_graph").asGraphInfos();

let unmountedGraph = graphList.filter((item) => item.status == "UNMOUNTED");
console.log(unmountedGraph.map((item) => item.name));
Output
[ 'DFS_EG', 'cyber', 'cyber2' ]

Schema

A Schema object has the following fields:

Field
Type
Description
namestringSchema name
descriptionstringSchema description
propertiesProperty[]Property list of the schema
totalNodesstringTotal number of nodes of the schema
totalEdgesstringTotal number of edges of the schema
TypeScript
let resp = await conn.uql("show().node_schema()", requestConfig);
let schemaList = resp.data?.alias("_nodeSchema").asSchemas();

for (let schema of schemaList) {
  console.log(schema.name, "has", schema.totalNodes, "nodes");
}
Output
default has 0 nodes
account has 111 nodes
movie has 92 nodes
country has 23 nodes
celebrity has 78 nodes

Property

A Property object has the following fields:

Field
Type
Description
namestringProperty name
descriptionstringProperty description
schemastringAssociated schema of the property
typestringProperty data type
ltestringProperty LTE status (true, false or creating)
extraPropertyExtraInfoExtra information of properties
TypeScript
let resp = await conn.uql("show().node_property(@user)", requestConfig);
let propertyList = resp.data?.alias("_nodeProperty").asProperties();

for (let property of propertyList) {
  if (property.lte == "true")
    console.log("LTE-ed property name:", property.name);
}
Output
LTE-ed property name: location

Algo

An Algo object has the following fields:

Field
Type
Description
clusterIdstringID of the cluster
namestringAlgorithm name
paramobjectParameters of the algorithm, including name, description, parameters, result_opt and version
detailstringAlgorithm detailed information
result_optobjectOptions for the algorithm result
TypeScript
let resp = await conn.uql("show().algo()");
let algoList = resp.data?.alias("_algoList").asAlgos();
console.log("Algo name:", algoList[0].param.name);
console.log("Algo version:", algoList[0].param.version);
console.log("Description:", algoList[0].param.description);
Output
Algo name: lpa
Algo version: 1.0.10
Description: label propagation algorithm

Exta

NOTE

An exta is a custom algorithm developed by users.

An Exta object has the following fields:

Field
Type
Description
authorstringExta author
detailstringContent of the YML configuration file of the Exta
namestringExta name
versionstringExta version
TypeScript
let resp = await conn.uql("show().exta()");
let extaList = resp.data?.alias("_extaList").asExtas();
console.log("Exta name:", extaList[0].name);
Output
Exta name: page_rank 1

Index

An Index object has the following fields:

Field
Type
Description
namestringIndex name
propertiesstringProperty name of the index
schemastringSchema name of the index
statusstringIndex status (done or creating)
sizestringIndex size in bytes
dbTypeUltipa.DBTypeIndex type (DBNODE or DBEDGE)
TypeScript
let resp = await conn.uql("show().index()");
let indexList = resp.data?.alias("_nodeIndex");
console.log(indexList.data);
Output
Table {
  name: '_nodeIndex',
  alias: '_nodeIndex',
  headers: [ 'name', 'properties', 'schema', 'status', 'size' ],
  rows: []
}
TypeScript
let resp = await conn.uql("show().fulltext()");
let indexList = resp.data?.alias("_nodeFulltext");
console.log(indexList.data);
Output
Table {
  name: '_nodeFulltext',
  alias: '_nodeFulltext',
  headers: [ 'name', 'properties', 'schema', 'status' ],
  rows: []
}

Privilege

A Privilege object has the following fields:

Field
Type
Description
systemPrivilegesstring[]System privileges
graphPrivilegesstring[]Graph privileges
TypeScript
let resp = await conn.uql("show().privilege()");
let privilegeList = resp.data?.alias("_privilege").asTable();

console.log("System privileges:", privilegeList.rows[0][1]);
Output
[TRUNCATE, COMPACT, CREATE_GRAPH, SHOW_GRAPH, DROP_GRAPH, ALTER_GRAPH, MOUNT_GRAPH, UNMOUNT_GRAPH, TOP, KILL, STAT, SHOW_POLICY, CREATE_POLICY, DROP_POLICY, ALTER_POLICY, SHOW_USER, CREATE_USER, DROP_USER, ALTER_USER, GRANT, REVOKE, SHOW_PRIVILEGE]

Policy

A Policy object has the following fields:

Field
Type
Description
namestringPolicy name
graph_privilegesGraphPrivilegeGraph privileges and the corresponding graphsets included in the policy
system_privilegesstring[]System privileges included in the policy
policiesstring[]Policies included in the policy
property_privilegesPropertyPrivilegeProperty privileges included in the policy
TypeScript
let resp = await conn.uql("show().policy()");
let policyList = resp.data?.alias("_policy");
console.log(policyList.data.rows[4]);
Output
[
  'policy',
  '{"amz":["SHOW_ALGO","CREATE_PROPERTY","CLEAR_TASK","RESUME_TASK","CREATE_BACKUP","SHOW_PROPERTY","SHOW_FULLTEXT","SHOW_INDEX"]}',
  '["GRANT","DROP_GRAPH","CREATE_USER","COMPACT","UNMOUNT_GRAPH","STAT","DROP_POLICY"]',
  '{"node":{"read":[],"write":[],"deny":[]},"edge":{"read":[],"write":[],"deny":[]}}',
  '["subpolicy"]'
]

User

A User object has the following fields:

Field
Type
Description
usernamestringUsername
createstringWhen the user was created
lastLoginstringWhen the user logged in last time
system_privilegesstring[]System privileges granted to the user
graph_privilegesGraphPrivilegeGraph privileges and the corresponding graphsets granted to the user
policiesstring[]Policies granted to the user
property_privilegesPropertyPrivilegeProperty privileges granted to the user
TypeScript
let resp = await conn.uql("show().user('Tester')");
let userList = resp.data.alias("_user").asTable();

console.log(userList.headers[0], ":", userList.rows[0][0]);
console.log(userList.headers[1], ":", userList.rows[0][1]);
console.log(userList.headers[2], ":", userList.rows[0][2]);
console.log(userList.headers[3], ":", userList.rows[0][3]);
console.log(userList.headers[4], ":", userList.rows[0][4]);
Output
username : Tester
create : 1721974206
graphPrivileges : {"Ad_Click":["FIND_EDGE","FIND_NODE"],"DFS_EG":["UPDATE","INSERT"]}
systemPrivileges : ["MOUNT_GRAPH"]
propertyPrivileges : {"node":{"read":[],"write":[["miniCircle","account","name"]],"deny":[]},"edge":{"read":[],"write":[],"deny":[]}} 

Stats

A Stats object has the following fields:

Field
Type
Description
cpuUsagestringCPU usage in percentage
memUsagestringMemory usage in megabytes
expiredDatestringExpiration date of the license
cpuCoresstringNumber of CPU cores
companystringCompany name
serverTypestringServer type
versionstringVersion of the server
TypeScript
let resp = await conn.stats();
console.log("CPU usage:", resp.data.cpuUsage, "%");
console.log("Memory usage:", resp.data.memUsage);
Output
CPU usage: 15.209929 %
Memory usage: 10418.183594

Process

A Process object has the following fields:

Field
Type
Description
process_idstringProcess ID
process_uqlstringThe UQL run with the process
statusstringProcess status
durationstringThe duration in seconds the task has run so far
TypeScript
let requestConfig = <RequestType.RequestConfig>{
  useMaster: true,
  graphSetName: "amz",
};

let resp = await conn.uql("top()", requestConfig);
let processList = resp.data?.alias("_top");
console.log(processList.data.rows[0][0]);
Output
a_1_3259_2

Task

A Task object has the following fields:

Field
Type
Description
paramobjectAlgorithm parameters and their corresponding values
task_infoobjectTask information including task_id, algo_name, start_time, TASK_STATUS, etc.
error_msgstringError message of the task
resultobjectAlgorithm result and statistics and their corresponding values
return_typeobjectResult return type
TypeScript
let requestConfig = <RequestType.RequestConfig>{
  useMaster: true,
  graphSetName: "miniCircle",
};

let resp = await conn.uql("show().task()", requestConfig);
let taskList = resp.data.alias("_task").asTasks();
console.log("Algo name:", taskList[0].task_info["algo_name"]);
console.log("Algo parameters:", taskList[0].param);
console.log("Result:", taskList[0].result);
Output
Algo name: louvain
Algo parameters: { phase1_loop_num: '20', min_modularity_increase: '0.001' }
Result: {
  community_count: '11',
  modularity: '0.532784',
  result_files: 'communityID'
}

Table

A Table object has the following fields:

Field
Type
Description
namestringTable name
headersobjectTable headers
rowsobjectTable rows

Methods on a Table object:

Method
Return
Description
toKV()List<Value>Convert all rows of the table to a key-value list.
TypeScript
let resp = await conn.uql(
  "find().nodes() as n return table(n._id, n._uuid) as myTable limit 5",
  requestConfig
);
let tableInfo = resp.data.alias("myTable").asTable();
console.log("2nd row in table:", tableInfo.toKV()[1]);
Output
2nd row in table: { 'n._id': 'ULTIPA8000000000000002', 'n._uuid': '2' }

Attr

An Attr object has the following fields:

Field
Type
Description
aliasstringAttr name
typenumberAttr type
type_descstringAttr type description
valuesobjectAttr rows
TypeScript
let resp = await conn.uql(
  "find().nodes({@account}) as n return n.year limit 5",
  requestConfig
);
let myAttr = resp.data.alias("n.year").asAttrs();
console.log(myAttr.values);
Output
[ 1978, 1989, 1982, 2007, 1973 ]