连接配置
与 Ultipa Graph 建立连接、发送请求时的配置项:
配置项 | 类型 | 说明 |
---|---|---|
Hosts | []string | Ultipa 数据库集群地址列表 |
Username | string | 用户名 |
Password | string | 密码 |
DefaultGraph | string | 建立连接时使用的图集名,通常为默认图集 default |
MaxRecvSIze | int | 接收数据的最大字节数 |
Consistency | bool | 是否使用读一致性 |
CurrentGraph | string | 运行时使用的图集名 |
Timeout | uint32 | 发送请求时的超时时间(秒) |
Debug | bool | 是否使用 debug 模式 |
HeartBeat | int | 所有实例的心跳时间(秒),0 则为关闭心跳时间 |
创建 Ultipa Client 连接
// 创建一个连接配置
config := configuration.NewUltipaConfig(&configuration.UltipaConfig{
Hosts: []string{"10.0.0.1:60061", "10.0.0.2:60061", "10.0.0.3:60061"},
Username: "root",
Password: "root",
})
// 获取 Ultipa Client 连接实例
client, err := sdk.NewUltipa(config)
请求配置
可以在任何一个 request API 中修改请求配置,可修改如下配置项:
配置项 | 类型 | 说明 |
---|---|---|
GraphName | string | 当前图集名 |
Timeout | uint32 | 超时时间(秒) |
Host | string | 向该主机发送请求 |
UseMaster | bool | 是否使用 leader 来保证读一致性 |
InsertType | ultipa.InsertType | 插入方式,InsertType_NORMAL, InsertType_OVERWRITE, InsertType_UPSERT |
CreateNodeIfNotExist | bool | 插入边时如果边的端点不存在,是否自动创建该点 |
// 使用当前的连接配置作为请求配置,发送 UQL 请求
resp, _ := client.UQL("find().nodes() as nodes return nodes limit 10", nil)
// 将超时时间修改为 20 秒,并发送 UQL 请求
rConfig := &configuration.RequestConfig{
Timeout: 20,
}
resp2, _ := client.UQL("find().nodes() as nodes return nodes limit 10", rConfig)