UltipaDocs
Try Playground
  • Introduction
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Installation
    • Connection
    • Request Configuration
    • UQL Execution
    • GQL Execution
    • Graphset Management
    • Schema and Property Management
    • Data Insertion and Deletion
    • Query Acceleration
    • Algorithm Management
    • Downloads and Exports
    • Process and Task Management
    • Access Management
    • Server Statistics
    • Result Processing
    • Types Mapping Ultipa and C#
  • RESTful API
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Convenience Methods

Schema and Property

This section introduces methods for managing schemas and properties in a graph.

Schema

ShowSchema()

Retrieves all schemas from the graph.

Parameters

  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Schema: A slice of pointers to the retrieved schemas.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves all schemas in the graph 'miniCircle'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schemas, _ := driver.ShowSchema(requestConfig)
for _, schema := range schemas {
    fmt.Println(schema.Name, schema.DBType)
}
Output
default DBNODE
account DBNODE
celebrity DBNODE
country DBNODE
movie DBNODE
default DBEDGE
direct DBEDGE
disagree DBEDGE
filmedIn DBEDGE
follow DBEDGE
wishlist DBEDGE
response DBEDGE
review DBEDGE

ShowNodeSchema()

Retrieves all node schemas from the graph.

Parameters

  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Schema: A slice of pointers to the retrieved schemas.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves all node schemas in the graph 'miniCircle'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schemas, _ := driver.ShowNodeSchema(requestConfig)
for _, schema := range schemas {
    fmt.Println(schema.Name, schema.DBType)
}
Output
default DBNODE
account DBNODE
celebrity DBNODE
country DBNODE
movie DBNODE

ShowEdgeSchema()

Retrieves all edge schemas from the graph.

Parameters

  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Schema: A slice of pointers to the retrieved schemas.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves all edge schemas in the graph 'miniCircle'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schemas, _ := driver.ShowEdgeSchema(requestConfig)
for _, schema := range schemas {
    fmt.Println(schema.Name, schema.DBType)
}
Output
default DBEDGE
direct DBEDGE
disagree DBEDGE
filmedIn DBEDGE
follow DBEDGE
wishlist DBEDGE
response DBEDGE
review DBEDGE

GetSchema()

Retrieves a specified schema from the graph.

Parameters

  • schemaName: string: Name of the schema.
  • dbType: ultipa.DBType: Type of the schema (node or edge).
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Schema: A pointer to the retrieved schema.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves the node schema named 'account'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schema, _ := driver.GetSchema("account", ultipa.DBType_DBNODE, requestConfig)
fmt.Println(schema.Total)
Output
111

GetNodeSchema()

Retrieves a specified node schema from the graph.

Parameters

  • schemaName: string: Name of the schema.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Schema: A pointer to the retrieved schema.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves the node schema named 'account'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schema, _ := driver.GetNodeSchema("account", requestConfig)
if schema != nil {
    for _, property := range schema.Properties {
        println(property.Name)
  }
} else {
    print("Not found")
}
Output
gender
year
industry
name

GetEdgeSchema()

Retrieves a specified edge schema from the graph.

Parameters

  • schemaName: string: Name of the schema.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Schema: A pointer to the retrieved schema.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves the edge schema named 'disagree'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schema, _ := driver.GetEdgeSchema("agree", requestConfig)
if schema != nil {
    for _, property := range schema.Properties {
        println(property.Name)
  }
} else {
    print("Not found")
}
Output
datetime
timestamp
targetPost

CreateSchema()

Creates a schema in the graph.

Parameters

  • schema: *structs.Schema: The schema to be created; the fields Name and DBType are mandatory, Properties and Description are optional.
  • isCreateProperties: bool: Whether to create properties associated with the schema.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

// Creates node schema 'utility' (with properties)

response1, _ := driver.CreateSchema(&structs.Schema{
    Name:   "utility",
    DBType: ultipa.DBType_DBNODE,
    Properties: []*structs.Property{
    	{Name: "name", Type: ultipa.PropertyType_STRING},
    	{Name: "type", Type: ultipa.PropertyType_UINT32}},
}, true, requestConfig)
fmt.Println(response1.Status.Code)

time.Sleep(3 * time.Second)

// Creates edge schema 'vote' (without properties)

response2, _ := driver.CreateSchema(&structs.Schema{
    Name:   "vote",
    DBType: ultipa.DBType_DBEDGE,
}, false, requestConfig)
fmt.Println(response2.Status.Code)
Output
SUCCESS
SUCCESS

CreateSchemaIfNotExist()

Creates a schema in the graph and returns whether a node or edge schema with the same name already exists.

Parameters

  • schema: *structs.Schema: The schema to be created; the fields Name and DBType are mandatory, Properties and Description are optional.
  • isCreateProperties: bool: Whether to create properties associated with the schema.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • ResponseWithExistCheck: Result of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

schema := &structs.Schema{
    Name:   "utility",
    DBType: ultipa.DBType_DBNODE,
    Properties: []*structs.Property{
    	{Name: "name", Type: ultipa.PropertyType_STRING},
    	{Name: "type", Type: ultipa.PropertyType_UINT32}},
}

result, _ := driver.CreateSchemaIfNotExist(schema, true, requestConfig)
fmt.Println("Does the schema already exist?", result.Exist)
if result.Response == nil {
    fmt.Println("Schema creation status: No response")
} else {
    fmt.Println("Schema creation status:", result.Response.Status.Code)
}

time.Sleep(3 * time.Second)
fmt.Println("----- Creates the schema again -----")

result_1, _ := driver.CreateSchemaIfNotExist(schema, true, requestConfig)
fmt.Println("Does the schema already exist?", result_1.Exist)
if result_1.Response == nil {
    fmt.Println("Schema creation status: No response")
} else {
    fmt.Println("Schema creation status:", result_1.Response.Status.Code)
}
Output
Does the schema already exist? false
Schema creation status: No response
----- Creates the schema again -----
Does the schema already exist? true
Schema creation status: No response

AlterSchema()

Alters the name and description a schema in the graph.

Parameters

  • originalSchema: *structs.Schema: The schema to be altered; the fields Name and DBType are mandatory.
  • newSchema: *structs.Schema: A pointer to the Schema struct used to set new Name and/or Description for the schema.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Renames the node schema 'utility' to 'securityUtility' in the graph 'miniCircle'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

oldSchema := &structs.Schema{Name: "utility", DBType: ultipa.DBType_DBNODE}
newSchema := &structs.Schema{Name: "securityUtility"}
response, _ := driver.AlterSchema(oldSchema, newSchema, requestConfig)
fmt.Println(response.Status.Code)
Output
SUCCESS

DropSchema()

Deletes a specified schema from the graph.

Parameters

  • schema: *structs.Schema: The schema to be dropped; the fields Name and DBType are mandatory.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Drops the edge schema 'vote' from the graph 'miniCircle'

requestConfig := &configuration.RequestConfig{
    Graph: "miniCircle",
}

response, _ := driver.DropSchema(&structs.Schema{Name: "vote", DBType: ultipa.DBType_DBEDGE}, requestConfig)
fmt.Println(response.Status.Code)
Output
SUCCESS

Property

ShowProperty()

Retrieves properties from the graph.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge, or global).
  • schemaName: string: Name of the schema; use an empty string ("") to target all schemas.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Property: A slice of pointers to the retrieved node properties.
  • []*structs.Property: A slice of pointers to the retrieved edge properties.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves all properties in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

nodeProperties, edgeProperties, _ := driver.ShowProperty(ultipa.DBType_DBGLOBAL, "", requestConfig)

fmt.Println("Node Properties:")
for _, nodeProperty := range nodeProperties {
    fmt.Println(nodeProperty.Name, "is associated with schema", nodeProperty.Schema)
}

fmt.Println("Edge Properties:")
for _, edgeProperty := range edgeProperties {
    fmt.Println(edgeProperty.Name, "is associated with schema", edgeProperty.Schema)
}
Output
Node Properties:
_id is associated with schema default
_id is associated with schema Paper
title is associated with schema Paper
score is associated with schema Paper
author is associated with schema Paper
Edge Properties:
weight is associated with schema Cites

ShowNodeProperty()

Retrieves node properties from the graph.

Parameters

  • schemaName: string: Name of the schema; use an empty string ("") to target all schemas.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Property: A slice of pointers to the retrieved properties.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves properties associated with the node schema 'Paper' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

properties, _ := driver.ShowNodeProperty("Paper", requestConfig)
for _, property := range properties {
    fmt.Println(property.Name, "-", property.Type)
}
Output
_id - STRING
title - STRING
score - INT32
author - STRING

ShowEdgeProperty()

Retrieves edge properties from the graph.

Parameters

  • schemaName: string: Name of the schema; use an empty string ("") to target all schemas.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • []*structs.Property: A slice of pointers to the retrieved properties.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves properties associated with the edge schema 'Cites' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

properties, _ := driver.ShowEdgeProperty("Cites", requestConfig)
for _, property := range properties {
    fmt.Println(property.Name, "-", property.Type)
}
Output
weight - INT32

GetProperty()

Retrieves a specified property from the graph.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge).
  • schemaName: string: Name of the schema.
  • propertyName: string: Name of the property.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Property: The retrieved property.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves node property 'title' associated with the node schema 'Paper' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

property, _ := driver.GetProperty(ultipa.DBType_DBNODE, "Paper", "title", requestConfig)
fmt.Println(property)
Output
&{title Paper STRING [] false false false   <nil>}

GetNodeProperty()

Retrieves a specified node property from the graph.

Parameters

  • schemaName: string: Name of the schema.
  • propertyName: string: Name of the property.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Property: The retrieved property.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves node property 'title' associated with the node schema 'Paper' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

property, _ := driver.GetNodeProperty("Paper", "title", requestConfig)
fmt.Println(property)
Output
&{title Paper STRING [] false false false   <nil>}

GetEdgeProperty()

Retrieves a specified edge property from the graph.

Parameters

  • schemaName: string: Name of the schema.
  • propertyName: string: Name of the property.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • *structs.Property: The retrieved property.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Retrieves edge property 'weight' associated with the edge schema 'Cites' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

property, _ := driver.GetEdgeProperty("Cites", "weight", requestConfig)
fmt.Println(property)
Output
&{weight Cites INT32 [] false false false   <nil>}

CreateProperty()

Creates a property in the graph.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge).
  • property: *structs.Property: The property to be created; the fields Name, Type (and SubType if the Type is SET or LIST), and Schema (sets to * to specify all schemas) are mandatory, Encrypt and Description are optional.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Creates a property 'year' for all node schemas, creates a property 'tags' for the node schema 'Paper'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

response1, _ := driver.CreateProperty(ultipa.DBType_DBNODE, &structs.Property{
    Name:    "year",
    Type:    ultipa.PropertyType_INT32,
    Encrypt: "AES128",
    Schema:  "*",
}, requestConfig)
fmt.Println(response1.Status.Code)

response2, _ := driver.CreateProperty(ultipa.DBType_DBNODE, &structs.Property{
    Name:     "tags",
    Type:     ultipa.PropertyType_SET,
    SubTypes: []ultipa.PropertyType{ultipa.PropertyType_STRING},
    Schema:   "Paper",
}, requestConfig)
fmt.Println(response2.Status.Code)
Output
SUCCESS
SUCCESS

CreatePropertyIfNotExist()

Creates a property in the graph and returns whether a node or edge property with the same name already exists for the specified schema.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge).
  • property: *structs.Property: The property to be created; the fields Name, Type (and SubType if the Type is SET or LIST), and Schema (sets to * to specify all schemas) are mandatory, Encrypt and Description are optional.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • ResponseWithExistCheck: Result of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

property := &structs.Property{
    Name:     "tags",
    Type:     ultipa.PropertyType_SET,
    SubTypes: []ultipa.PropertyType{ultipa.PropertyType_STRING},
    Schema:   "Paper",
}

result, _ := driver.CreatePropertyIfNotExist(ultipa.DBType_DBNODE, property, requestConfig)
fmt.Println("Does the property already exist?", result.Exist)
if result.Response == nil {
    fmt.Println("Property creation status: No response")
} else {
    fmt.Println("Property creation status:", result.Response.Status.Code)
}

time.Sleep(3 * time.Second)
fmt.Println("----- Creates the property again -----")

result_1, _ := driver.CreatePropertyIfNotExist(ultipa.DBType_DBNODE, property, requestConfig)
fmt.Println("Does the property already exist?", result_1.Exist)
if result_1.Response == nil {
    fmt.Println("Property creation status: No response")
} else {
    fmt.Println("Property creation status:", result_1.Response.Status.Code)
}
Output
Does the property already exist? false
Property creation status: SUCCESS
----- Creates the property again -----
Does the property already exist? true
Property creation status: No response

AlterProperty()

Alters the name and description a property in the graph.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge).
  • originProp: *structs.Property: The property to be altered; the fields Name and Schema (writes * to specify all schemas) are mandatory.
  • newProp: *structs.Property: A pointer to the Property struct used to set new Name and/or Description for the property.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Renames the property 'tags' of the node schema 'Paper' to 'keywords' in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

response, _ := driver.AlterProperty(ultipa.DBType_DBNODE, &structs.Property{
    Name:   "tags",
    Schema: "Paper",
}, &structs.Property{
    Name: "keywords",
}, requestConfig)
fmt.Print(response.Status.Code)
Output
SUCCESS

DropProperty()

Deletes specified properties from the graph.

Parameters

  • dbType: ultipa.DBType: Type of the property (node or edge).
  • property: *structs.Property: The property to be droppped; the fields Name and Schema (writes * to specify all schemas) are mandatory.
  • config: *configuration.RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
  • error: An error object that contains details about any issues encountered during the operation. If the operation succeeds, nil is returned.
Go
// Drops the property 'tags' of the node schema in the graph 'citation'

requestConfig := &configuration.RequestConfig{
    Graph: "citation",
}

response, _ := driver.DropProperty(ultipa.DBType_DBNODE, &structs.Property{
    Name:   "tags",
    Schema: "Paper",
}, requestConfig)
fmt.Print(response.Status.Code)
Output
SUCCESS

Full Example

Go
package main

import (
	"fmt"
	"log"

	ultipa "github.com/ultipa/ultipa-go-driver/v5/rpc"
	"github.com/ultipa/ultipa-go-driver/v5/sdk"
	"github.com/ultipa/ultipa-go-driver/v5/sdk/configuration"
	"github.com/ultipa/ultipa-go-driver/v5/sdk/structs"
)

func main() {
	config := &configuration.UltipaConfig{
		// URI example:	Hosts: []string{"mqj4zouys.us-east-1.cloud.ultipa.com:60010"},
		Hosts:    []string{"192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"},
		Username: "<usernmae>",
		Password: "<password>",
	}

	driver, err := sdk.NewUltipaDriver(config)
	if err != nil {
		log.Fatalln("Failed to connect to Ultipa:", err)
	}

	// Creates schemas and properties in the graph 'social'

	requestConfig := &configuration.RequestConfig{
		Graph: "social",
	}

	user := &structs.Schema{
		Name:   "user",
		DBType: ultipa.DBType_DBNODE,
		Properties: []*structs.Property{
			{Name: "name", Type: ultipa.PropertyType_STRING},
			{Name: "age", Type: ultipa.PropertyType_INT32},
			{Name: "score", Type: ultipa.PropertyType_DECIMAL, DecimalExtra: &structs.DecimalExtra{Precision: 25, Scale: 10}},
			{Name: "birthday", Type: ultipa.PropertyType_DATE},
			{Name: "active", Type: ultipa.PropertyType_BOOL},
			{Name: "location", Type: ultipa.PropertyType_POINT},
			{Name: "interests", Type: ultipa.PropertyType_LIST, SubTypes: []ultipa.PropertyType{ultipa.PropertyType_STRING}},
			{Name: "permissionCodes", Type: ultipa.PropertyType_SET, SubTypes: []ultipa.PropertyType{ultipa.PropertyType_INT32}},
		},
	}

	product := &structs.Schema{
		Name:   "product",
		DBType: ultipa.DBType_DBNODE,
		Properties: []*structs.Property{
			{Name: "name", Type: ultipa.PropertyType_STRING},
			{Name: "price", Type: ultipa.PropertyType_FLOAT},
		},
	}

	follows := &structs.Schema{
		Name:   "follows",
		DBType: ultipa.DBType_DBEDGE,
		Properties: []*structs.Property{
			{Name: "createdOn", Type: ultipa.PropertyType_TIMESTAMP},
			{Name: "weight", Type: ultipa.PropertyType_FLOAT},
		},
	}

	purchased := &structs.Schema{
		Name:   "purchased",
		DBType: ultipa.DBType_DBEDGE,
	}

	schemas := []*structs.Schema{user, product, follows, purchased}
	for _, schema := range schemas {
		response, _ := driver.CreateSchema(schema, true, requestConfig)
		fmt.Println(response.Status.Code)
	}
}