UltipaConfig
UltipaConfig
defines the information of server needed when connecting to an Ultipa graph database.
Item |
Type |
Default |
Description |
---|---|---|---|
Hosts | []string | IP addresses of cluster servers (comma-separated) or host URL (excluding "https://" or "http://") | |
Username | string | Username of server | |
Password | string | Password of server | |
DefaultGraph | string | Name of graphset to use | |
MaxRecvSIze | int | 10MB | Max byte when receiving data |
Consistency | bool | false | Whether to use the leader host to guarantee Consistency Read |
CurrentGraph | string | default | Name of current graphset |
CurrentClusterId | string | Cluster ID of name server | |
Timeout | uint32 | 1000 | Timeout seconds for any request |
Debug | bool | false | Whether to use the debug mode |
HeartBeat | int | 0 | Heartbeat (in seconds) for all instances, set to 0 to turn off heartbeat |
Connect to a Cluster
Example: Connect to a cluster and configure by code
func TestMisc(t *testing.T) {
config := configuration.NewUltipaConfig(&configuration.UltipaConfig{
Hosts: []string{"192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"},
Username: "***",
Password: "***",
})
conn, _ := sdk.NewUltipa(config)
testResult, _ := conn.Test()
println(testResult)
}
Connect to Ultipa Cloud
Example: Connect to an instance on Ultipa Cloud, and configure by code
func GetClient1(hosts []string, graphName string) (*api.UltipaAPI, error) {
var err error
config, _ := configuration.NewUltipaConfig(&configuration.UltipaConfig{
Hosts: []string{"xaznryn5s.us-east-1.cloud.ultipa.com:60010"},
Username: "root",
Password: "123456",
DefaultGraph: "Sample_Graphset",
Debug: true,
})
client, err = sdk.NewUltipa(config)
if err != nil {
log.Fatalln(err)
}
return client, err
}
YAML Configuration File
yaml stores the information of server needed when connecting to an Ultipa graph database.
Variable in yaml | Item in UltipaConfig |
---|---|
hosts | Hosts |
username | Username |
password | Password |
default_graph | DefaultGraph |
crt | Crt |
max_recv_size | MaxRecvSIze |
consistency | Consistency |
current_graph | CurrentGraph |
current_cluster_id | CurrentClusterId |
timeout | Timeout |
debug | Debug |
heart_beat | HeartBeat |
Example: Create a server connection using configuration file. Place the yaml file 'testConfig.yml' in the path of current Go file
hosts:
- "192.168.1.85:60061"
- "192.168.1.86:60061"
- "192.168.1.87:60061"
username: ***
password: ***
default_graph: amz
timeout:: 300
func TestMisc(t *testing.T) {
config, _ := configuration.LoadConfigFromYAML("./testConfig.yml")
conn, _ := sdk.NewUltipa(config)
testResult, _ := conn.Test()
println(testResult)
}
RequestConfig
RequestConfig
defines the information needed when sending non-insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
GraphName | string | name of graphset to use, or use DefaultGraph configured when establishing server connection if not set | |
Timeout | uint32 | 0 | timeout seconds for the request, or use timeout configured when establishing server connection if not set |
ClusterId | string | cluster ID of name server | |
Host | string | send the request to a designated host, or sent to a random host if not set | |
UseMaster | bool | false | if send the request to the leader to guarantee Consistency Read |
UseControl | bool | false | if send the request to control node |
RequestType | RequestType or int32 | 0 | send the requset to a node according to the request type: RequestType_Write or 1, send to leader RequestType_Task or 2, send to algo RequestType_Normal or 3, send to a random host |
Uql | string | UQL for internal program |
Example: Create a server connection using graphset 'default' and send a UQL to write back result to graphset 'amz', send this task to algo
func TestMisc(t *testing.T) {
config := configuration.NewUltipaConfig(&configuration.UltipaConfig{
Hosts: []string{"192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"},
Username: "***",
Password: "***",
})
conn, _ := sdk.NewUltipa(config)
requestConfig := &configuration.RequestConfig{
GraphName: "amz",
RequestType: configuration.RequestType_Task,
}
conn.UQL("algo(degree).params().write({db:{property: \"degree\"}})", requestConfig)
}
InsertRequestConfig
InsertRequestConfig
defines the information needed when sending insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
GraphName | string | name of graphset to use, or use DefaultGraph configured when establishing server connection if not set | |
Timeout | uint32 | 0 | timeout seconds for the request, or use timeout configured when establishing server connection if not set |
ClusterId | string | cluster ID of name server | |
Host | string | send the request to a designated host, or sent to a random host if not set | |
UseMaster | bool | false | if send the request to the leader to guarantee Consistency Read |
UseControl | bool | false | if send the request to control node |
RequestType | RequestType or int32 | 0 | send the requset to a node according to the request type: RequestType_Write or 1, send to leader RequestType_Task or 2, send to algo RequestType_Normal or 3, send to a random host |
Uql | string | UQL for internal program | |
InsertType | ultipa.InsertType or int32 | 0 | insert mode: InsertType_NORMAL or 0 InsertType_OVERWRITE or 1 InsertType_UPSERT or 2 |
CreateNodeIfNotExist | bool | false | if create start/end nodes of edge when the end nodes do not exist in the graphset |
Example: Create a server connection using graphset 'default', and insert nodes into graphset 'test' under overwrite mode
func TestMisc(t *testing.T) {
config := configuration.NewUltipaConfig(&configuration.UltipaConfig{
Hosts: []string{"192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"},
Username: "***",
Password: "***",
})
conn, _ := sdk.NewUltipa(config)
requestConfig := &configuration.RequestConfig{
GraphName: "test",
}
insertRequestConfig := &configuration.InsertRequestConfig{
RequestConfig: requestConfig,
InsertType: ultipa.InsertType_OVERWRITE,
}
var nodes []*structs.Node
newNode1 := structs.NewNode()
newNode1.Schema = "card"
newNode1.ID = "ULTIPA8000000000000001"
newNode1.Set("amount", float32(3235.2))
nodes = append(nodes, newNode1)
newNode2 := structs.NewNode()
newNode2.Schema = "client"
newNode2.ID = "ULTIPA8000000000000007"
newNode2.Set("level", int32(77))
nodes = append(nodes, newNode2)
conn.InsertNodesBatchAuto(nodes, insertRequestConfig)
}