This section introduces methods on a Connection object for managing schemas and properties of nodes and edges in a graphset.
Each example focuses solely on the method's usage. For a complete code example, please refer to the full example.
Retrieves all nodes and edge schemas from the current graphset.
Parameters:
RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Schema: The list of all schemas in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all schemas in graphset 'UltipaTeam' and prints their names and types requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } mySchema, _ := conn.ShowSchema(requestConfig) for _, item := range mySchema { fmt.Print("Schema name:", item.Name, " Schema type:", item.Type, "\n") }
OutputSchema name:default Schema type:node Schema name:member Schema type:node Schema name:organization Schema type:node Schema name:default Schema type:edge Schema name:reportsTo Schema type:edge Schema name:relatesTo Schema type:edge{ Name: 'relatesTo', dbType: 'DBEDGE' } ]
Retrieves a node or edge schema from the current graphset.
Parameters:
string: Name of the schema.ultipa.DBType: Type of the schema (node or edge).RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Schema: The retrieved schema.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves node schema 'member' and edge schema 'connectsTo' in graphset 'UltipaTeam', and prints all their information requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } nodeSchema, _ := conn.GetSchema("member", ultipa.DBType_DBNODE, requestConfig) if nodeSchema != nil { println("Name:", nodeSchema.Name, "Type:", nodeSchema.Type+" schema", " Number:", nodeSchema.Total) } else { println("Not exists") } edgeSchema, _ := conn.GetSchema("connectsTo", ultipa.DBType_DBEDGE, requestConfig) if edgeSchema != nil { println("Name:", edgeSchema.Name, "Type:", edgeSchema.Type+" schema", " Number:", edgeSchema.Total) } else { println("Not exists") }
OutputName: member Type: node schema Number: 7 Not exists
Retrieves all node schemas from the current graphset.
Parameters:
RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Schema: The list of all node schemas in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all node schemas in graphset 'UltipaTeam' and prints their names requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } nodeSchema, _ := conn.ShowNodeSchema(requestConfig) for _, item := range nodeSchema { println(item.Name) }
Outputdefault member organization
Retrieves all edge schemas from the current graphset.
Parameters:
RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Schema: The list of all edge schemas in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all edge schemas in graphset 'UltipaTeam' and prints their names requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } edgeSchema, _ := conn.ShowEdgeSchema(requestConfig) for _, item := range edgeSchema { println(item.Name) }
Outputdefault reportsTo relatesTo
Retrieves a node schema from the current graphset.
Parameters:
string: Name of the schema.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Schema: The retrieved node schema.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves node schema 'member' in graphset 'UltipaTeam' and prints its properties requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } mySchema, _ := conn.GetNodeSchema("member", requestConfig) println(utils.ToJSONString(mySchema.Properties))
Output[{"Name":"title","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"member","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""},{"Name":"profile","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"member","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""},{"Name":"age","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"member","Type":1,"SubTypes":null,"Extra":"{}","Encrypt":""}]
Retrieves an edge schema from the current graphset.
Parameters:
string: Name of the schema.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Schema: The retrieved edge schema.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves edge schema 'relatesTo' in graphset 'UltipaTeam' and prints its properties requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } mySchema, _ := conn.GetEdgeSchema("relatesTo", requestConfig) println(utils.ToJSONString(mySchema.Properties))
Output[{"Name":"type","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"relatesTo","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""}]
Creates a new schema in the current graphset.
Parameters:
Schema: The schema to be created; the fields Name and DBType must be set, Desc (short for description) and Properties are optional.bool: Whether to create properties, the default is false.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.GorequestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Creates node schema 'utility' (with properties) in graphset 'UltipaTeam' and prints all its information newNodeSchema, _ := conn.CreateSchema(&structs.Schema{Name: "utility", Properties: []*structs.Property{{Name: "name", Type: ultipa.PropertyType_STRING}, {Name: "purchaseDate", Type: ultipa.PropertyType_DATETIME}}, DBType: ultipa.DBType_DBNODE, Desc: "Office utilities"}, true, requestConfig) println("Node Schema Creation Succeeds: ", newNodeSchema.Status.IsSuccess()) println(utils.JSONString(newNodeSchema)) // Creates edge schema 'managedBy' (without properties) in graphset 'UltipaTeam' and prints all its information newEdgeSchema, _ := conn.CreateSchema(&structs.Schema{Name: "managedBy", DBType: ultipa.DBType_DBEDGE}, false, requestConfig) println("Edge Schema Creation Succeeds: ", newEdgeSchema.Status.IsSuccess()) println(utils.JSONString(newEdgeSchema))
OutputNode Schema Creation Succeeds: true {"DataItemMap":{},"Reply":{"status":{},"statistics":{"table_name":"statistics","headers":[{"property_name":"node_affected","property_type":7},{"property_name":"edge_affected","property_type":7},{"property_name":"total_time_cost","property_type":7},{"property_name":"engine_time_cost","property_type":7}],"table_rows":[{"values":["MA==","MA==","MA==","MA=="]}]},"explain_plan":{}},"Status":{"Message":"","Code":0},"Statistic":{"NodeAffected":0,"EdgeAffected":0,"TotalCost":0,"EngineCost":0},"ExplainPlan":{"Explain":[]},"AliasList":null,"Resp":{"ClientStream":{}}} Edge Schema Creation Succeeds: true {"DataItemMap":{},"Reply":{"status":{},"statistics":{"table_name":"statistics","headers":[{"property_name":"node_affected","property_type":7},{"property_name":"edge_affected","property_type":7},{"property_name":"total_time_cost","property_type":7},{"property_name":"engine_time_cost","property_type":7}],"table_rows":[{"values":["MA==","MA==","MA==","MA=="]}]},"explain_plan":{}},"Status":{"Message":"","Code":0},"Statistic":{"NodeAffected":0,"EdgeAffected":0,"TotalCost":0,"EngineCost":0},"ExplainPlan":{"Explain":[]},"AliasList":null,"Resp":{"ClientStream":{}}}
Creates a new schema in the current graphset, handling cases where the given schema name already exists by ignoring the error.
Parameters:
Schema: The schema to be created; the fields Name and DBType must be set, Desc and Properties are optional.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
bool: Whether the schema exists.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.GorequestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Creates one schema in graphset 'UltipaTeam' and prints if the schema already exists cre1, _ := conn.CreateSchemaIfNotExist(&structs.Schema{Name: "utility", DBType: ultipa.DBType_DBNODE, Desc: "Office utilities"}, requestConfig) println("Schema already exists: ", cre1) // Creates the same schema again and prints if the schema already exists cre2, _ := conn.CreateSchemaIfNotExist(&structs.Schema{Name: "utility", DBType: ultipa.DBType_DBNODE, Desc: "Office utilities"}, requestConfig) println("Schema already exists: ", cre2)
OutputSchema already exists: false Schema already exists: true
Alters the name and description of one existing schema in the current graphset by its name.
Parameters:
Schema: The existing schema to be altered; the fields Name and DBType must be set.Schema: The new configuration for the existing schema; either or both of the fields Name and Desc (short for description) must be set.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Renames the node schema 'utility' to 'securityUtility' and removes its description in graphset 'UltipaTeam' requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } resp, _ := conn.AlterSchema(&structs.Schema{Name: "utility", DBType: ultipa.DBType_DBNODE}, &structs.Schema{Name: "securityUtility"}, requestConfig) println("Operation succeeds:", resp.Status.IsSuccess())
OutputOperation succeeds: true
Drops one schema from the current graphset by its name.
Parameters:
Schema: The existing schema to be dropped; the fields Name and DBType must be set.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Drops the node schema 'utility' in graphset 'UltipaTeam' requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } resp, _ := conn.DropSchema(&structs.Schema{Name: "utility", DBType: ultipa.DBType_DBNODE}, requestConfig) println("Operation succeeds:", resp.Status.IsSuccess())
OutputOperation succeeds: true
Retrieves custom properties of nodes or edges from the current graphset.
Parameters:
DBType: Type of the property (node or edge).string: Name of the schema.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Property: The list of all properties retrieved in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all node properties in graphset 'UltipaTeam' and prints their names and associated schemas requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } resp, _ := conn.ShowNodeSchema(requestConfig) for _, item := range resp { proList, _ := conn.ShowProperty(ultipa.DBType_DBNODE, item.Name, requestConfig) for _, pro := range proList { println(pro.Name, "is associated with schema named", item.Name) } }
Outputtitle is associated with schema named member profile is associated with schema named member age is associated with schema named member name is associated with schema named organization logo is associated with schema named organization
Retrieves custom properties of nodes from the current graphset.
Parameters:
string: Name of the schema.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Property: The list of all properties retrieved in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all custom properties of node schema 'member' in graphset 'UltipaTeam' and prints the count requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } myCount, _ := conn.ShowNodeProperty("member", requestConfig) println(len(myCount))
Output3
Retrieves custom properties of edges from the current graphset.
Parameters:
string: Name of the schema.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
[]Property: The list of all properties retrieved in the current graphset.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves all custom properties of edge schema 'relatesTo' in graphset 'UltipaTeam' and prints their names requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } myEdge, _ := conn.ShowEdgeProperty("relatesTo", requestConfig) if myEdge != nil { for _, item := range myEdge { println(item.Name) } } else { println("No property") }
Outputtype
Retrieves a custom property of nodes or edges from the current graphset.
Parameters:
DBType: Type of the property (node or edge).string: Name of the schema.string: Name of the property.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Property: The retrieved property.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves node property @member.title in graphset 'UltipaTeam' and prints all its information requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } proInfo, _ := conn.GetProperty(ultipa.DBType_DBNODE, "member", "title", requestConfig) println(utils.ToJSONString(proInfo))
Output{"Name":"title","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"member","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""}
Retrieves a custom property of nodes from the current graphset.
Parameters:
string: Name of the schema.string: Name of the property.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Property: The retrieved property.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves node property @member.title in graphset 'UltipaTeam' and prints all its information requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } proInfo, _ := conn.GetNodeProperty("member", "title", requestConfig) println(utils.ToJSONString(proInfo))
Output{"Name":"title","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"member","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""}
Retrieves a custom property of edges from the current graphset.
Parameters:
string: Name of the schema.string: Name of the property.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Property: The retrieved property.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Retrieves edge property @relatesTo.type in graphset 'UltipaTeam' and prints all its information requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } proInfo, _ := conn.GetEdgeProperty("relatesTo", "type", requestConfig) println(utils.ToJSONString(proInfo))
Output{"Name":"type","Desc":"","Lte":false,"Read":false,"Write":false,"Schema":"relatesTo","Type":7,"SubTypes":null,"Extra":"{}","Encrypt":""}
Creates a new property for a node or edge schema in the current graphset.
Parameters:
DBType: Type of the property (node or edge).string: Name of the schema, write * to specify all schemas.Property: The property to be created; the fields Name and Type must be set.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.Go// Creates two properties for node schema 'member' in graphset 'UltipaTeam' and prints error codes requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } prop1 := &structs.Property{Name: "startDate", Type: ultipa.PropertyType_DATETIME} new1, _ := conn.CreateProperty(ultipa.DBType_DBNODE, "member", prop1, requestConfig) println("Operation succeeds:", new1.Status.IsSuccess()) prop2 := &structs.Property{Name: "age", Type: ultipa.PropertyType_INT32} new2, _ := conn.CreateProperty(ultipa.DBType_DBNODE, "member", prop2, requestConfig) println("Operation succeeds:", new2.Status.IsSuccess())
OutputOperation succeeds: true Operation succeeds: true
Creates a new property for a node or edge schema in the current graphset, handling cases where the given property name already exists by ignoring the error.
Parameters:
DBType: Type of the property (node or edge).string: Name of the schema, write * to specify all schemas.Property: The property to be created; the fields Name and Type must be set.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
bool: Whether the property exists.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.GorequestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Creates a property for node schema 'member' in graphset 'UltipaTeam' and prints if the schema already exists myProp := &structs.Property{Name: "startDate", Type: ultipa.PropertyType_DATETIME} new1, _ := conn.CreatePropertyIfNotExist(ultipa.DBType_DBNODE, "member", myProp, requestConfig) println("Property already exists:", new1) // Creates the same property again in graphset 'UltipaTeam' and prints if the schema already exists new2, _ := conn.CreatePropertyIfNotExist(ultipa.DBType_DBNODE, "member", myProp, requestConfig) println("Property already exists:", new2)
OutputProperty already exists: false Property already exists: true
Alters the name and description of one existing custom property in the current graphset by its name.
Parameters:
DBType: Type of the property (node or edge).Property: The existing property to be altered; the fields Name and Schema (write * to specify all schemas) must be set.Property: The new configuration for the existing property; either or both of the fields Name and Desc must be set.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.GorequestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Rename properties 'name' associated with all node schemas to `Name` in graphset 'UltipaTeam' myAlt, _ := conn.AlterProperty(ultipa.DBType_DBNODE, &structs.Property{Name: "name", Schema: "*"}, &structs.Property{Name: "Name"}, requestConfig) println("Operation succeeds:", myAlt.Status.IsSuccess())
OutputOperation succeeds: true
Drops one custom property from the current graphset by its name and the associated schema.
Parameters:
DBType: Type of the property (node or edge).string: Name of the schema.string: Name of the property.RequestConfig (Optional): Configuration settings for the request. If nil is provided, the function will use default configuration settings.Returns:
Response: Result of the request.error: An error object containing details about any issues that occurred. nil is returned if the operation is successful.GorequestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Drops properties 'startDate' assocaited with all node schemas in graphset 'UltipaTeam' and prints error code drop1, _ := conn.DropProperty(ultipa.DBType_DBNODE, "*", "startDate", requestConfig) println("Operation succeeds:", drop1.Status.IsSuccess()) // Drops node property @member.name in graphset 'UltipaTeam' and prints error code drop2, _ := conn.DropProperty(ultipa.DBType_DBNODE, "member", "name", requestConfig) println("Operation succeeds:", drop2.Status.IsSuccess())
OutputOperation succeeds: true Operation succeeds: true
Gopackage main import ( ultipa "github.com/ultipa/ultipa-go-sdk/rpc" "github.com/ultipa/ultipa-go-sdk/sdk" "github.com/ultipa/ultipa-go-sdk/sdk/configuration" "github.com/ultipa/ultipa-go-sdk/sdk/structs" "github.com/ultipa/ultipa-go-sdk/utils" ) func main() { // Connection configurations //URI example: Hosts:=[]string{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"} config, _ := configuration.NewUltipaConfig(&configuration.UltipaConfig{ Hosts: []string{"192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"}, Username: "***", Password: "***", }) // Establishes connection to the database conn, _ := sdk.NewUltipa(config) // Request configurations requestConfig := &configuration.RequestConfig{ UseMaster: true, GraphName: "UltipaTeam", } // Creates node schema 'utility' (with properties) in graphset 'UltipaTeam' and prints error code newNodeSchema, _ := conn.CreateSchema(&structs.Schema{Name: "utility", Properties: []*structs.Property{{Name: "name", Type: ultipa.PropertyType_STRING}, {Name: "purchaseDate", Type: ultipa.PropertyType_DATETIME}}, DBType: ultipa.DBType_DBNODE, Desc: "Office utilities"}, true, requestConfig) println("Node Schema Creation Succeeds: ", newNodeSchema.Status.IsSuccess()) println(utils.JSONString(newNodeSchema)) }