UQLResponse | UQLReply
Sending uql()
request will return class ULTIPA.UQLResponse。
UQLResponse has below fields:
Field | Type | Description |
---|---|---|
data? | ULTIPA.UQLReply | result of UQL |
req? | any | request of UQL |
explainPlans? | ExplainPlan | UQL statement explanation tree |
status | Status | status of request execution |
statistic? | Statistic | statistics of request execution, including timecost, metadata affected, etc. |
The field data
of ULTIPA.UQLResponse is a class ULTIPA.UQLReply.
UQLReply has below fields:
Field | Type | Description |
---|---|---|
datas | DataItem[] | aliases and values (DataItem) of each return value |
aliasMap | object | aliases and types of each return value |
statistics | Statistics | statistics of request execution, including timecost, metadata affected, etc. |
explainPlansTreeTopNode | PlanNode | the top node of UQL statement explanation tree |
UQLReply has below methods:
Method | Type | Description |
---|---|---|
toJSON() | object | convert UQLReply (excluding aliasMap ) to json object |
singleDataNodes() | Node[] | acquire the first alias (must be NODE type) as Node[] |
singleDataEdges() | Edge[] | acquire the first alias (must be EDGE type) as Edge[] |
singleDataPaths() | Path[] | acquire the first alias (must be PATH type) as Path[] |
singleDataAttrs() | AttrAlias | acquire the first alias (must be ATTR type) as AttrAlias |
singleDataArrays() | any[][] | acquire the first alias (must be ARRAY type) as any[][] |
singleDataTables() | Table | acquire the first alias (must be TABLE type) as Table |
getTables() | Table[] | convert all aliases of TABLE type to Table[] |
get(index: number) | DataItem | acquire an alias of datas as DataItem by index |
alias(alias: string) | DataItem | acquire an alias of datas as DataItem by name |
Alias types such as NODE, EDGE and PATH can be converted to corresponding classes using methods of class DataItem, see next chapter Alias Structs for detail.
toJSON()
Example: Send UQL insert().into(@default).nodes({})
to server and print the result in JSON format
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn'
let resp = await conn.uql("insert().into(@default).nodes({})");
console.log(resp.data?.toJSON());
};
sdkUsage();
Output:
{
statistics: { totalCost: 57, engineCost: 0, nodeAffected: 1, edgeAffected: 0 },
explainPlansTreeTopNode: null,
datas: []
}
get()
Example: Send UQL return now() as currentTime, pi() as PI
to server and print the first alias
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn'
let resp = await conn.uql("return now() as currentTime, pi() as PI");
console.log(resp.data?.get(0));
};
sdkUsage();
Output:
DataItem {
data: {
alias: 'currentTime',
type: 4,
type_desc: 'RESULT_TYPE_ATTR',
values: [ '2024-03-14 07:33:12.803414' ]
},
alias: 'currentTime',
type: 4,
type_desc: 'RESULT_TYPE_ATTR'
}
alias()
Example: Send UQL return now() as currentTime, pi() as PI
to server and print the second alias
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn'
let resp = await conn.uql("return now() as currentTime, pi() as PI");
console.log(resp.data?.alias("PI"));
};
sdkUsage();
Output:
DataItem {
data: {
alias: 'PI',
type: 4,
type_desc: 'RESULT_TYPE_ATTR',
values: [ '3.14159265358979' ]
},
alias: 'PI',
type: 4,
type_desc: 'RESULT_TYPE_ATTR'
}