全部查询方法均支持使用可选配置参数(RequestConfig
或InsertRequestConfig
)来自定义向数据库发出的请求。
RequestConfig
RequestConfig
用来定义向数据库发送非插入请求时所需的配置。
using Newtonsoft.Json;
using UltipaSharp;
using UltipaSharp.configuration;
using UltipaSharp.connection;
using Logger = UltipaSharp.utils.Logger;
using Microsoft.Extensions.Logging;
class Program
{
static async Task Main(string[] args)
{
var ultipa = new Ultipa(new UltipaConfig()
{
//URI示例: Hosts = new[]{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"}
Hosts = new[]{ "192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061" },
CurrentGraph = "default",
Username = "***",
Password = "***",
});
Console.WriteLine("Connected to the graph database!");
var requestConfig = new RequestConfig()
{
Graph = "miniCircle",
UseMaster = true,
RequestType = RequestType.Normal
};
var res = await ultipa.Uql("find().nodes() return nodes{*} limit 2", requestConfig);
Logger.Global.LogInformation(JsonConvert.SerializeObject(res?.Alias("nodes")?.AsNodes()));
}
}
RequestConfig
包含如下字段:
字段 | 类型 | 默认值 | 描述 |
---|---|---|---|
Graph |
string? | 要使用的图名称。如果没有设置,则使用建立连接时配置的 CurrentGraph |
|
Timeout |
uint? | 请求超时阈值(秒) | |
ClusterId |
string? | 指定要使用的集群 | |
Host |
string? | 将请求发送到指定的主机节点,如果没有设置,则发送到随机的主机节点 | |
UseMaster |
bool | false | 设置为true 时,将请求发送到leader节点以保证一致性读取 |
UseControl |
bool | false | 设置为 true 时,将请求发送到控制节点 |
RequestType |
RequestType | RequestType.Normal | 根据请求类型将请求发送到节点:RequestType.Write :发送到leader节点RequestType.Task :发送到算法节点RequestType.Normal :发送到随机主机节点 |
Uql |
string? | 内部程序使用的UQL语句 | |
Timezone |
string? | 要使用的时区 | |
TimezoneOffset |
int? | 所用时区与UTC的时间差(秒) | |
ThreadNumber |
int? | 线程数 |
InsertRequestConfig
InsertRequestConfig
用于定义向数据库发送数据插入或删除请求时所需的配置。
using Newtonsoft.Json;
using UltipaSharp;
using UltipaSharp.configuration;
using UltipaSharp.connection;
using Logger = UltipaSharp.utils.Logger;
using Microsoft.Extensions.Logging;
using UltipaService;
using UltipaSharp.structs;
using Property = UltipaSharp.structs.Property;
using Schema = UltipaSharp.structs.Schema;
class Program
{
static void Main(string[] args)
{
var ultipa = new Ultipa(new UltipaConfig()
{
Hosts = new[]{ "192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061" },
Username = "***",
Password = "***",
});
Console.WriteLine("Connected to the graph database!");
var schema = new Schema()
{
Name = "User",
DbType = DBType.Dbnode,
Properties = new()
{
new ()
{
Name = "name",
Type = PropertyType.String,
},
new(){
Name = "age",
Type = PropertyType.Int32
},
new()
{
Name = "birth",
Type = PropertyType.Datetime
}
}
};
var nodes = new List<Node>()
{
new()
{
Id = "C#1",
Schema = schema.Name,
Values =
new (){
{"name", "name1"},
{"age", 28},
{"birth", new DateTime(1989,9,12)}
}
}
};
// Specifies 'test' as the target graphset and sets the insert mode to OVERWRITE
var insertConfig = new InsertRequestConfig()
{
Graph = "test",
InsertType = InsertType.Overwrite,
};
var res = ultipa.InsertNodesBatchBySchema(schema,nodes,insertConfig);
Logger.Global.LogInformation(JsonConvert.SerializeObject(res));
}
}
InsertRequestConfig
包含以下字段:
字段 | 类型 | 默认值 | 描述 |
---|---|---|---|
Graph |
string? | 要使用的图名称。如果没有设置,则使用建立连接时配置的 CurrentGraph |
|
Timeout |
uint? | 请求超时阈值(秒) | |
ClusterId |
string? | 指定要使用的集群 | |
Host |
string? | 将请求发送到指定的主机节点,如果没有设置,则发送到随机的主机节点 | |
UseMaster |
bool | false | 设置为true 时,将请求发送到leader节点以保证一致性读取 |
UseControl |
bool | false | 设置为true 时,将请求发送到控制节点。 |
RequestType |
RequestType | RequestType.Normal | 根据请求类型将请求发送到节点:RequestType.Write :发送到 leader 节点RequestType.Task :发送到算法节点RequestType.Normal :发送到随机主机节点 |
Uql |
string? | 内部程序使用的 UQL 语句 | |
Timezone |
string? | 要使用的时区 | |
TimezoneOffset |
int? | 所用时区与 UTC 的时间差(秒) | |
ThreadNumber |
int? | 线程数 | |
InsertType |
UltipaService.InsertType | InsertType.Normal | 插入模式:InsertType.Normal (正常插入)、InsertType.Overwrite (插入覆盖)、InsertType.Upsert (插入更新) |
CreateNodeIfNotExist |
bool | true | 当目标节点在图中不存在时,是否创建边的起点/终点 |
Silent |
bool | true | 插入成功后,是否保持静默,即是否返回插入的节点或边 |