graphson

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 5 Imported by: 8

README

graphson

A library to deserialize neptune data

Contributing

See CONTRIBUTING for details.

License

Copyright © 2021, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorPropertyNotFound       = errors.New("property not found")
	ErrorPropertyIsMeta         = errors.New("meta-property found where multi-property expected")
	ErrorPropertyIsMulti        = errors.New("multi-property found where singleton expected")
	ErrorUnexpectedPropertyType = errors.New("property value could not be cast into expected type")
)

Functions

func DeserializeInt32

func DeserializeInt32(rawResponse json.RawMessage) (num int32, err error)

func DeserializeListFromBytes

func DeserializeListFromBytes(rawResponse json.RawMessage) ([]json.RawMessage, error)

DeserializeListFromBytes validates that the provided RawMessage corresponds to a g:List type and returns a slice of RawMessage values

func DeserializeMapFromBytes

func DeserializeMapFromBytes(rawResponse json.RawMessage) (resMap map[string]json.RawMessage, err error)

func DeserializeNumber

func DeserializeNumber(rawResponse json.RawMessage) (count int64, err error)

DeserializeNumber returns the count from the g:List'd database response

func DeserializePropertiesFromBytes

func DeserializePropertiesFromBytes(rawResponse json.RawMessage, resMap map[string][]interface{}) (err error)

DeserializePropertiesFromBytes is for converting vertex .properties() results into a map

func DeserializeStringListFromBytes

func DeserializeStringListFromBytes(rawResponse json.RawMessage) (vals []string, err error)

DeserializeStringListFromBytes get a g:List value which should be a a list of strings, return those

func EdgesMatch

func EdgesMatch(edge1, edge2 Edge) (bool, string)

func GenericValuesMatch

func GenericValuesMatch(gv1, gv2 GenericValue) (bool, string)

func VerticesMatch

func VerticesMatch(vertex1, vertex2 Vertex) bool

Types

type CleanEdge

type CleanEdge struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

func ConvertToCleanEdges

func ConvertToCleanEdges(edges Edges) []CleanEdge

type CleanVertex

type CleanVertex struct {
	Id    string `json:"id"`
	Label string `json:"label"`
}

func ConvertToCleanVertices

func ConvertToCleanVertices(vertices []Vertex) []CleanVertex

type Edge

type Edge struct {
	Type  string    `json:"@type"`
	Value EdgeValue `json:"@value"`
}

type EdgeProperty

type EdgeProperty struct {
	Type  string            `json:"@type"`
	Value EdgePropertyValue `json:"@value"`
}

type EdgePropertyValue

type EdgePropertyValue struct {
	Label string `json:"key"`
	// Value GenericValue `json:"value"` // this works when value is NOT a string
	Value json.RawMessage `json:"value"`
}

type EdgeValue

type EdgeValue struct {
	ID         string                  `json:"id"`
	Label      string                  `json:"label"`
	InVLabel   string                  `json:"inVLabel"`
	OutVLabel  string                  `json:"outVLabel"`
	InV        string                  `json:"inV"`
	OutV       string                  `json:"outV"`
	Properties map[string]EdgeProperty `json:"properties"`
}

type Edges

type Edges []Edge

func DeserializeEdges

func DeserializeEdges(rawResponse string) (Edges, error)

func DeserializeListOfEdgesFromBytes

func DeserializeListOfEdgesFromBytes(rawResponse json.RawMessage) (Edges, error)

type GenericValue

type GenericValue struct {
	Type  string      `json:"@type"`
	Value interface{} `json:"@value"`
}

func DeserializeGenericValue

func DeserializeGenericValue(rawResponse string) (response GenericValue, err error)

func DeserializeSingleFromBytes

func DeserializeSingleFromBytes(rawResponse json.RawMessage) (gV GenericValue, err error)

DeserializeSingleFromBytes get a g:List value which should be a singular item, returns that item

type GenericValues

type GenericValues []GenericValue

func DeserializeGenericValues

func DeserializeGenericValues(rawResponse string) (GenericValues, error)

type ListEdges

type ListEdges struct {
	Type  string `json:"@type"`
	Value Edges  `json:"@value"`
}

ListEdges contains a slice of Edges as value

type ListVertices

type ListVertices struct {
	Type  string   `json:"@type"`
	Value []Vertex `json:"@value"`
}

ListVertices contains a slice of Vertices as value

type Raw

type Raw struct {
	Type  string          `json:"@type"`
	Value json.RawMessage `json:"@value"`
}

Raw contains a RawMessage as value

type RawSlice

type RawSlice struct {
	Type  string            `json:"@type"`
	Value []json.RawMessage `json:"@value"`
}

RawSlice contains a slice of RawMessages as value

type Vertex

type Vertex struct {
	Type  string      `json:"@type"`
	Value VertexValue `json:"@value"`
}

func DeserializeListOfVerticesFromBytes

func DeserializeListOfVerticesFromBytes(rawResponse json.RawMessage) ([]Vertex, error)

DeserializeListOfVerticesFromBytes returns a slice of Vertex from the graphson rawResponse g:List of vertex

func DeserializeVertices

func DeserializeVertices(rawResponse string) ([]Vertex, error)

DeserializeVertices converts a graphson string to a slice of Vertex

func DeserializeVerticesFromBytes

func DeserializeVerticesFromBytes(rawResponse json.RawMessage) ([]Vertex, error)

DeserializeVerticesFromBytes returns a slice of Vertex from the graphson rawResponse list of vertex

func (Vertex) GetID

func (v Vertex) GetID() string

GetID returns the string ID for the given vertex

func (Vertex) GetLabel

func (v Vertex) GetLabel() (string, error)

GetLabel returns the string label for the given vertex, or an error if >1

func (Vertex) GetLabels

func (v Vertex) GetLabels() (labels []string)

GetLabels returns the []string labels for the given vertex

func (Vertex) GetMetaProperty

func (v Vertex) GetMetaProperty(key string) (metaMap map[string][]string, err error)

GetMetaProperty returns a map[string]string for the given property `key`

func (Vertex) GetMultiProperty

func (v Vertex) GetMultiProperty(key string) (vals []string, err error)

GetMultiProperty returns the ([]string) values for the given property `key` will return an error if the property is not the correct type

func (Vertex) GetMultiPropertyAs

func (v Vertex) GetMultiPropertyAs(key, wantType string) (vals []interface{}, err error)

GetMultiPropertyAs returns the values for the given property `key` as type `wantType` will return an error if the property is not a set of the given `wantType` (string, bool, int64)

func (Vertex) GetMultiPropertyBool

func (v Vertex) GetMultiPropertyBool(key string) (vals []bool, err error)

GetMultiPropertyBool returns the ([]bool) values for the given property `key` will return an error if the property is not the correct type

func (Vertex) GetMultiPropertyInt32

func (v Vertex) GetMultiPropertyInt32(key string) (vals []int32, err error)

GetMultiPropertyInt32 returns the ([]int32) values for the given property `key` will return an error if the property is not the correct type

func (Vertex) GetMultiPropertyInt64

func (v Vertex) GetMultiPropertyInt64(key string) (vals []int64, err error)

GetMultiPropertyInt64 returns the ([]int64) values for the given property `key` will return an error if the property is not the correct type

func (Vertex) GetProperty

func (v Vertex) GetProperty(key string) (val string, err error)

GetProperty returns the single string value for a given property `key` will return an error if the property is not a single string

func (Vertex) GetPropertyBool

func (v Vertex) GetPropertyBool(key string) (val bool, err error)

GetPropertyBool returns the single bool value for a given property `key` will return an error if the property is not a single string

func (Vertex) GetPropertyInt32

func (v Vertex) GetPropertyInt32(key string) (val int32, err error)

GetPropertyInt32 returns the single int32 value for a given property `key` will return an error if the property is not a single string

func (Vertex) GetPropertyInt64

func (v Vertex) GetPropertyInt64(key string) (val int64, err error)

GetPropertyInt64 returns the single int64 value for a given property `key` will return an error if the property is not a single string

type VertexProperty

type VertexProperty struct {
	Type  string              `json:"@type"`
	Value VertexPropertyValue `json:"@value"`
}

type VertexPropertyValue

type VertexPropertyValue struct {
	ID    GenericValue `json:"id"`
	Label string       `json:"label"`
	Value interface{}  `json:"value"`
}

type VertexValue

type VertexValue struct {
	ID         string                      `json:"id"`
	Label      string                      `json:"label"`
	Properties map[string][]VertexProperty `json:"properties"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL