download()
Method and interface:
download(params: RequestType.Download,
commonReq: RequestType.CommonStreamRequire
): Promise<ClientReadableStream<DownloadFileReply>>
interface Download {
fileName: string;
taskId: string;
}
interface CommonStreamRequire extends RequestConfig {
stream: Stream;
}
interface Stream {
onStart?: () => void;
onClose?: () => void;
onData: (data: any) => void | Promise<any>;
onEnd: () => void;
onError?: (err: Error) => void;
onPause?: () => void;
onReadable?: () => void;
onResume?: () => void;
package_limit?: number;
}
Example: Download file 'degree_test' from algorithm task 134 to the current project with filename 'test.csv'. The algorithm task was executed against graphset 'test'
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
var fs = require("fs");
var path = __dirname + "\\test.csv";
console.log(path);
let res = await new Promise(async (resolve, reject) => {
let v = await conn.download(
{ fileName: "degree_test", taskId: "134" },
{
graphSetName: "test",
stream: {
onData: (data) => {
console.log(data.toString().substring(0, 100));
fs.writeFile(path, data.toString(), function (err: any) {
if (err) throw err;
console.log('file saved!');
});
},
onEnd: () => {
resolve("success");
},
onError(err) {
resolve(err);
}
}
}
)
});
};
sdkUsage().then(console.log).catch(console.log);
export()
Method and interface:
export(params: RequestType.Export,
commonReq: RequestType.CommonStreamRequire
): Promise<ClientReadableStream<ExportReply>>
interface Export {
dbType: ULTIPA.DBType;
schema: string;
limit: number;
properties: string[];
}
interface CommonStreamRequire extends RequestConfig {
stream: Stream;
}
interface Stream {
onStart?: () => void;
onClose?: () => void;
onData: (data: any) => void | Promise<any>;
onEnd: () => void;
onError?: (err: Error) => void;
onPause?: () => void;
onReadable?: () => void;
onResume?: () => void;
package_limit?: number;
}
Example: Export 100 nodes from schema 'default' of graphset 'test', carring properties @default.name
and @default.age
import { ConnectionPool,ULTIPA } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// omit code of establishing server connection 'conn' using graphset 'default'
await conn.export(
{
dbType: ULTIPA.DBType.DBNODE,
schema: "default",
limit: 100,
properties: ["name", "age"]
},
{
graphSetName: "test",
stream: {
onData: (data) => {
console.log(data);
},
onEnd: () => {
console.log("export finish");
}
}
}
);
};
sdkUsage();