UltipaDocs
Try Playground
  • Introduction
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Go

Data Types

The GQLDB Go driver supports a comprehensive set of data types for storing and querying graph data. This guide covers property types, enums, and type conversions.

Property Types

The PropertyType constants define all supported data types:

Go
import gqldb "github.com/gqldb/gqldb-go"

Numeric Types

TypeDescriptionGo Type
PropertyTypeInt3232-bit signed integerint32
PropertyTypeUint3232-bit unsigned integeruint32
PropertyTypeInt6464-bit signed integerint64
PropertyTypeUint6464-bit unsigned integeruint64
PropertyTypeFloat32-bit floating pointfloat32
PropertyTypeDouble64-bit floating pointfloat64
PropertyTypeDecimalArbitrary precision decimalDecimal

String Types

TypeDescriptionGo Type
PropertyTypeStringVariable-length stringstring
PropertyTypeTextLong textstring

Boolean and Null

TypeDescriptionGo Type
PropertyTypeBoolBoolean valuebool
PropertyTypeNullNull valuenil
PropertyTypeUnsetUnset/unknown typenil

Binary

TypeDescriptionGo Type
PropertyTypeBlobBinary data[]byte

Date and Time Types

TypeDescriptionGo Type
PropertyTypeTimestampUnix timestamp with nanosecondstime.Time
PropertyTypeDatetimeDate and time (deprecated)time.Time
PropertyTypeDateDate onlyLocalDateTime
PropertyTypeLocalDatetimeLocal date and timeLocalDateTime
PropertyTypeZonedDatetimeDate and time with timezoneZonedDateTime
PropertyTypeLocalTimeLocal time of dayLocalTime
PropertyTypeZonedTimeTime with timezoneZonedTime

Duration Types

TypeDescriptionGo Type
PropertyTypeYearToMonthYear-month durationYearToMonth
PropertyTypeDayToSecondDay-second durationDayToSecond

Geospatial Types

TypeDescriptionGo Type
PropertyTypePoint2D geographic pointPoint
PropertyTypePoint3D3D pointPoint3D

Collection Types

TypeDescriptionGo Type
PropertyTypeListOrdered list[]interface{}
PropertyTypeSetUnordered unique setSet
PropertyTypeMapKey-value mapmap[string]interface{}
PropertyTypeVectorNumeric vectorVector

Graph Types

TypeDescriptionGo Type
PropertyTypeNodeGraph node*Node
PropertyTypeEdgeGraph edge*Edge
PropertyTypePathGraph pathPath

PropertyType Constants

Go
const (
    PropertyTypeUnset
    PropertyTypeInt32
    PropertyTypeUint32
    PropertyTypeInt64
    PropertyTypeUint64
    PropertyTypeFloat
    PropertyTypeDouble
    PropertyTypeString
    PropertyTypeDatetime      // Deprecated, use PropertyTypeTimestamp
    PropertyTypeTimestamp
    PropertyTypeText
    PropertyTypeBlob
    PropertyTypePoint
    PropertyTypeDecimal
    PropertyTypeList
    PropertyTypeSet
    PropertyTypeMap
    PropertyTypeNull
    PropertyTypeBool
    PropertyTypeLocalDatetime
    PropertyTypeZonedDatetime
    PropertyTypeDate
    PropertyTypeZonedTime
    PropertyTypeLocalTime
    PropertyTypeYearToMonth
    PropertyTypeDayToSecond
    PropertyTypeRecord
    PropertyTypePoint3D
    PropertyTypeVector
    PropertyTypeTable
    PropertyTypePath
    PropertyTypeError
    PropertyTypeNode
    PropertyTypeEdge
)

GraphType Constants

Go
const (
    GraphTypeOpen     // Schema-less graph
    GraphTypeClosed   // Schema-enforced graph
    GraphTypeOntology // Ontology-enabled graph
)

HealthStatus Constants

Go
const (
    HealthStatusUnknown
    HealthStatusServing
    HealthStatusNotServing
    HealthStatusServiceUnknown
)

CacheType Constants

Go
const (
    CacheTypeAll
    CacheTypeAST
    CacheTypePlan
)

Type Structs

Node Types

Go
// Data for inserting nodes
type NodeData struct {
    ID         string
    Labels     []string
    Properties map[string]interface{}
}

// Node from query results
type Node struct {
    ID         string
    Labels     []string
    Properties map[string]interface{}
}

Edge Types

Go
// Data for inserting edges
type EdgeData struct {
    Label      string
    FromNodeID string
    ToNodeID   string
    Properties map[string]interface{}
}

// Edge from query results
type Edge struct {
    ID         string
    Label      string
    FromNodeID string
    ToNodeID   string
    Properties map[string]interface{}
}

Path Type

Go
type Path struct {
    Nodes []*Node
    Edges []*Edge
}

Geospatial Types

Go
type Point struct {
    Latitude  float64
    Longitude float64
}

type Point3D struct {
    X float64
    Y float64
    Z float64
}

Duration Types

Go
type YearToMonth struct {
    Months int32
}

type DayToSecond struct {
    Nanos int64
}

Vector Type

Go
type Vector struct {
    Values []float32
}

func (v Vector) Dimension() int {
    return len(v.Values)
}

TypedValue

The driver uses TypedValue internally for type-safe data transfer:

Go
type TypedValue struct {
    Type   PropertyType
    Data   []byte
    IsNull bool
}

// Convert to Go type
func (tv *TypedValue) ToGo() (interface{}, error)

Creating TypedValues

Go
// Create from Go value
tv, err := gqldb.NewTypedValue(42)
tv, err = gqldb.NewTypedValue("hello")
tv, err = gqldb.NewTypedValue(3.14)
tv, err = gqldb.NewTypedValue(true)

Creating Parameters

Go
// Create query parameter
param, err := gqldb.NewParameter("name", "Alice")
param, err = gqldb.NewParameter("age", 30)

Type Conversion Examples

Working with Dates

Go
// Insert with date
client.Gql(ctx, `
    INSERT (e:Event {
        _id: 'e1',
        name: 'Conference',
        date: DATE('2024-06-15'),
        startTime: DATETIME('2024-06-15T09:00:00Z')
    })
`, nil)

// Query and convert
response, _ := client.Gql(ctx, "MATCH (e:Event) RETURN e.date, e.startTime", nil)
row := response.First()
if row != nil {
    date, _ := row.Get(0)
    startTime, _ := row.Get(1)
    fmt.Printf("Event date: %v\n", date)
    fmt.Printf("Start time: %v\n", startTime)
}

Working with Points

Go
// Insert with location
client.Gql(ctx, `
    INSERT (p:Place {
        _id: 'p1',
        name: 'Office',
        location: POINT(37.7749, -122.4194)
    })
`, nil)

// Query and access point
response, _ := client.Gql(ctx, "MATCH (p:Place) RETURN p.location", nil)
row := response.First()
if row != nil {
    location, _ := row.Get(0)
    if pt, ok := location.(*gqldb.Point); ok {
        fmt.Printf("Lat: %f, Lng: %f\n", pt.Latitude, pt.Longitude)
    }
}

Working with Collections

Go
// Insert with list and map
client.Gql(ctx, `
    INSERT (u:User {
        _id: 'u1',
        name: 'Alice',
        tags: ['developer', 'blogger'],
        metadata: {level: 5, premium: true}
    })
`, nil)

// Query collections
response, _ := client.Gql(ctx, "MATCH (u:User) RETURN u.tags, u.metadata", nil)
row := response.First()
if row != nil {
    tags, _ := row.Get(0)
    metadata, _ := row.Get(1)
    fmt.Printf("Tags: %v\n", tags)
    fmt.Printf("Metadata: %v\n", metadata)
}

Complete Example

Go
package main

import (
    "context"
    "fmt"
    "log"
    "time"

    gqldb "github.com/gqldb/gqldb-go"
)

func main() {
    config := gqldb.NewConfigBuilder().
        Hosts("192.168.1.100:9000").
        Timeout(30 * time.Second).
        Build()

    client, err := gqldb.NewClient(config)
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    ctx := context.Background()
    client.Login(ctx, "admin", "password")
    client.CreateGraph(ctx, "typeDemo", gqldb.GraphTypeOpen, "")
    client.UseGraph(ctx, "typeDemo")

    // Insert data with various types
    client.Gql(ctx, `
        INSERT (u:User {
            _id: 'u1',
            name: 'Alice',
            age: 30,
            balance: 1234.56,
            active: true,
            joined: DATE('2023-01-15'),
            location: POINT(40.7128, -74.0060),
            tags: ['developer', 'mentor'],
            settings: {theme: 'dark', notifications: true}
        })
    `, nil)

    // Query and check types
    response, _ := client.Gql(ctx, `
        MATCH (u:User {_id: 'u1'})
        RETURN u.name, u.age, u.balance, u.active, u.joined,
               u.location, u.tags, u.settings
    `, nil)

    row := response.First()
    if row != nil {
        name, _ := row.GetString(0)
        age, _ := row.GetInt(1)
        balance, _ := row.GetFloat(2)
        active, _ := row.GetBool(3)
        joined, _ := row.Get(4)
        location, _ := row.Get(5)
        tags, _ := row.Get(6)
        settings, _ := row.Get(7)

        fmt.Printf("Name (string): %s\n", name)
        fmt.Printf("Age (int64): %d\n", age)
        fmt.Printf("Balance (float64): %.2f\n", balance)
        fmt.Printf("Active (bool): %v\n", active)
        fmt.Printf("Joined: %v\n", joined)
        fmt.Printf("Location: %v\n", location)
        fmt.Printf("Tags: %v\n", tags)
        fmt.Printf("Settings: %v\n", settings)

        // Check property types
        fmt.Println("\nProperty types:")
        for i, tv := range row.Values {
            fmt.Printf("  Column %d: %v\n", i, tv.Type)
        }
    }

    client.DropGraph(ctx, "typeDemo", true)
}