Data Type
Ultipa property types and NodeJS data types are correlated as following pairs:
Ultipa | NodeJS |
---|---|
string | string |
text | string |
float | string |
double | number |
int32 | number |
uint32 | number |
int64 | string |
uint64 | string |
datetime | string |
timestamp | number |
Please note that
int64
anduint64
in Ultipa should be presented asstring
in NodeJS since thenumber
in NodeJS has limited value range; similarly,float
in Ultipa is also presented asstring
for the sake of accuracy.
insertNodesBatchBySchema()
InsertNodesBatchBySchema()
will insert multiple nodes of a particular node schema.
Method and interface:
insertNodesBatchBySchema(schema: ULTIPA.Schema,
rows: ULTIPA.Node[],
config: RequestType.InsertRequestConfig
): Promise<ULTIPA.Response<ResponseType.InsertNodes>>
type Schema = {
name: string;
properties: Property[];
}
type Property = {
name: string;
type: PropertyType;
}
class Node {
schema: string;
id: string;
uuid: string;
values: object;
}
Example: Insert multiple nodes into schema 'card' of graphset 'test', use normal insert mode
import { ConnectionPool, RequestType, ULTIPA } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
let schema = <ULTIPA.Schema>{
name: "card",
properties: [
{
name: "balance",
type: ULTIPA.PropertyType.PROPERTY_FLOAT,
},
{
name: "level",
type: ULTIPA.PropertyType.PROPERTY_INT32,
},
],
};
let node1 = new ULTIPA.Node();
node1.values = { balance: 3235.2, level: 2 };
let node2 = new ULTIPA.Node();
node2.values = { level: 1 };
let nodes = [node1, node2];
let insertRequestConfig = <RequestType.InsertRequestConfig>{
graphSetName: "test",
insertType: ULTIPA.InsertType.INSERT_TYPE_NORMAL,
};
let resp = await conn.insertNodesBatchBySchema(schema, nodes, insertRequestConfig);
console.log(resp.status.code_desc);
};
sdkUsage();
insertNodesBatchAuto()
InsertNodesBatchAuto()
will insert multiple nodes of multiple node schemas. Make sure the nodes carry schemas.
Method and interface:
insertNodesBatchAuto(rows: ULTIPA.Node[],
config?: RequestType.InsertRequestConfig
): Promise<ULTIPA.Response<ResponseType.InsertNodes>>
class Node {
schema: string;
id: string;
uuid: string;
values: object;
}
Example: Insert multiple nodes into multiple schemas of graphset 'test', use upsert mode
import { ConnectionPool, RequestType, ULTIPA } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
let node1 = new ULTIPA.Node();
node1.schema = "card";
node1.id = "ULTIPA8000000000000001";
node1.values = { level: 1 };
let node2 = new ULTIPA.Node();
node2.schema = "client";
node2.id = "ULTIPA800000000000002C";
node2.values = { name: "Grace" };
let nodes = [node1, node2];
let insertRequestConfig = <RequestType.InsertRequestConfig>{
graphSetName: "test",
insertType: ULTIPA.InsertType.INSERT_TYPE_UPSERT,
};
let resp = await conn.insertNodesBatchAuto(nodes, insertRequestConfig);
console.log(resp.status.code_desc);
};
sdkUsage();
insertEdgesBatchBySchema()
insertEdgesBatchBySchema()
will insert multiple edges of a particular edge schema.
Method and interface:
insertEdgesBatchBySchema(schema: ULTIPA.Schema,
rows: ULTIPA.Edge[],
config: RequestType.InsertRequestConfig
): Promise<ULTIPA.Response<ResponseType.InsertNodes>>
type Schema = {
name: string;
properties: Property[];
}
type Property = {
name: string;
type: PropertyType;
}
class Edge {
schema: string;
from: string;
to: string;
uuid: string;
from_uuid: string;
to_uuid: string;
values: object;
}
Example: Insert multiple edges into schema 'transfer' of graphset 'test', use normal insert mode, allowing start/end nodes to be created
import { ConnectionPool, RequestType, ULTIPA } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
let schema = <ULTIPA.Schema>{
name: "transfer",
properties: [
{
name: "amount",
type: ULTIPA.PropertyType.PROPERTY_DOUBLE,
},
{
name: "remark",
type: ULTIPA.PropertyType.PROPERTY_STRING,
},
],
};
let edge1 = new ULTIPA.Edge();
edge1.from = "CARD00001";
edge1.to = "CARD00004";
edge1.values = { amount: 140.5, remark: "retail" };
let edge2 = new ULTIPA.Edge();
edge2.from = "CARD00002";
edge2.to = "CARD00004";
edge2.values = { amount: 1999 };
let edges = [edge1, edge2];
let insertRequestConfig = <RequestType.InsertRequestConfig>{
graphSetName: "test",
insertType: ULTIPA.InsertType.INSERT_TYPE_NORMAL,
createNodeIfNotExist: true,
};
let resp = await conn.insertEdgesBatchBySchema(schema, edges, insertRequestConfig);
console.log(resp.status.code_desc);
};
sdkUsage();
insertEdgesBatchAuto()
insertEdgesBatchAuto()
will insert multiple edges of multiple edge schemas. Make sure the edges carry schemas.
Method and interface:
insertEdgesBatchAuto(rows: ULTIPA.Edge[],
config: RequestType.InsertRequestConfig
): Promise<ULTIPA.Response<ResponseType.InsertEdges>>
class Edge {
schema: string;
from: string;
to: string;
uuid: string;
from_uuid: string;
to_uuid: string;
values: object;
}
Example: Insert multiple edges into multiple schemas of graphset 'test', use overwrite mode, allowing start/end nodes to be created
import { ConnectionPool, RequestType, ULTIPA } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
let edge1 = new ULTIPA.Edge();
edge1.schema = "transfer";
edge1.uuid = "33";
edge1.from = "CARD00001";
edge1.to = "CARD00004";
edge1.values = { amount: 164.5 };
let edge2 = new ULTIPA.Edge();
edge2.schema = "has";
edge2.from = "ULTIPA0000001";
edge2.to = "CARD00004";
let edges = [edge1, edge2];
let insertRequestConfig = <RequestType.InsertRequestConfig>{
graphSetName: "test",
insertType: ULTIPA.InsertType.INSERT_TYPE_OVERWRITE,
createNodeIfNotExist: true,
};
let resp = await conn.insertEdgesBatchAuto(edges, insertRequestConfig);
console.log(resp.status.code_desc);
};
sdkUsage();