全部查询方法均支持使用可选配置参数(RequestConfig或InsertRequestConfig)来自定义向数据库发出的请求。您可使用该参数指定各种设置,如图集名称、超时时间和主机,根据自身需求定制请求。
RequestConfig
RequestConfig用来定义向数据库发送非插入请求时所需的配置。
from ultipa import Connection, UltipaConfig
from ultipa.configuration.RequestConfig import RequestConfig
ultipaConfig = UltipaConfig()
# URI 示例: ultipaConfig.hosts = ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"]
ultipaConfig.username = "<username>"
ultipaConfig.password = "<password>"
ultipaConfig.defaultGraph = "default"
Conn = Connection.NewConnection(defaultConfig=ultipaConfig)
requestConfig = RequestConfig(graphName = "UltipaTeam")
schemas = Conn.showSchema(requestConfig)
for schema in schemas:
    print(schema.name, "type:", schema.DBType, "total", schema.total)
RequestConfig 包含如下字段:
| 字段 | 类型 | 默认 | 描述 | 
|---|---|---|---|
| graphName | str | 待使用的图集;若未设定,则为建立连接时配置的 defaultGraph | |
| timeoutWithSeconds | int | 3600 | 请求超时时间,单位为秒;若未设定,则为建立连接时配置的 timeoutWithSeconds | 
| useHost | str | 发送请求至指定的主机节点;若未设定,则发送至任意主机节点 | |
| useMaster | bool | false | 若设定为true,则发送请求至主节点以确保一致性读取 | 
| threadNum | int | 线程数 | |
| retry | Retry | 重试次数,包括 current(可选,默认为 0)和max(可选,默认为 3)。其中,current表示初始重试次数,max表示最大允许的重试次数。 | |
| timeZone | str | 时区,格式如:Asia/Shanghai,如果没有设置,则使用建立连接时配置的 timeZone | |
| timeZoneOffset | int/str | 目标时区与UTC的时差,以秒(整数)或5字符字符串(如 +0700 和 -0430)表示;如果没有设置,则使用建立连接时配置的 timeZoneOffset | 
InsertRequestConfig
InsertRequestConfig 用来定义向数据库发送插入或删除数据请求时所需的配置。
from ultipa.configuration.InsertRequestConfig import InsertRequestConfig
from ultipa import Connection, UltipaConfig, Node
from ultipa.structs import InsertType
ultipaConfig = UltipaConfig()
# URI示例:ultipaConfig.hosts = ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"]
ultipaConfig.username = "<username>"
ultipaConfig.password = "<password>"
Conn = Connection.NewConnection(defaultConfig=ultipaConfig)
# 指定图集test为目标图集,并将插入模式设置为OVERWRITE
insertRequestConfig = InsertRequestConfig(
    insertType=InsertType.OVERWRITE,
    graphName="test"
)
nodes = [
    Node(schema="client", id="CLIENT00001"),
    Node(schema="card", id="CARD00004")
]
  
Conn.insertNodesBatchAuto(nodes, insertRequestConfig)
InsertRequestConfig 包含如下字段:
| 字段 | 类型 | 默认 | 描述 | 
|---|---|---|---|
| graphName | str | 待使用的图集;若未设定,则为建立连接时配置的 defaultGraph | |
| timeout | int | 3600 | 请求超时时间,单位为秒;若未设定,则为建立连接时配置的 timeout | 
| retry | Retry | 重试次数,包括 current(可选,默认为0)和max(可选,默认为3)。其中,current表示初始重试次数,max表示最大允许的重试次数。 | |
| useHost | str | 发送请求至指定的主机节点;若未设定,则发送至任意主机节点 | |
| useMaster | bool | False | 若设定为true,则发送请求至主节点以确保一致性读取 | 
| insertType | InsertType | NORMAL | 插入模式,包括 NORMAL,UPSERT和OVERWRITE | 
| silent | bool | True | 插入成功后,是否保持静默,即是否返回插入的节点或边 | 
| createNodeIfNotExist | bool | False | 若边的终点不在图集里,是否要创建对应的点 | 
| timeZone | str | 时区,格式如:Asia/Shanghai,如果没有设置,则使用建立连接时配置的 timeZone | |
| timeZoneOffset | int/str | 目标时区与UTC的时差,以秒(整数)或5字符字符串(如+0700和-0430)表示;如果没有设置,则使用建立连接时配置的 timeZoneOffset | 
