download()
方法及相关接口:
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;
}
示例:使用异步接口下载算法任务 134 中的文件 degree_test 至当前项目中且命名为 'test.csv',原算法任务针对图集 test 进行运算
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// 创建名为 conn 的连接并使用 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();
export()
方法及相关接口:
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;
}
示例:使用异步接口从图集 test 导出 100 个 default 点,要求导出属性 'name' 和 'age'
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
let sdkUsage = async () => {
// 创建名为 conn 的连接并使用 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();