opengraph

package
v0.4.17 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(ctx context.Context, db graph.Database, w io.Writer) error

Export reads all nodes and edges from db and writes them as an indented JSON Document to w.

func Validate

func Validate(doc Document) error

Validate checks a Document for structural errors. It returns nil for an empty graph.

Types

type Document

type Document struct {
	Graph Graph `json:"graph"`
}

Document is the top-level container for an OpenGraph JSON file.

func ParseDocument

func ParseDocument(r io.Reader) (Document, error)

ParseDocument decodes and validates a Document from r without writing to a database.

type Edge

type Edge struct {
	StartID    string         `json:"start_id"`
	EndID      string         `json:"end_id"`
	Kind       string         `json:"kind"`
	Properties map[string]any `json:"properties,omitempty"`
}

Edge represents a directed relationship between two nodes.

type Graph

type Graph struct {
	Nodes []Node `json:"nodes"`
	Edges []Edge `json:"edges"`
}

Graph contains the nodes and edges of the graph.

func (Graph) Kinds

func (g Graph) Kinds() (nodeKinds, edgeKinds graph.Kinds)

Kinds returns the unique node and edge kinds found in the graph.

type IDMap

type IDMap map[string]graph.ID

IDMap maps document string node IDs to their database-assigned IDs.

func Load

func Load(ctx context.Context, db graph.Database, r io.Reader) (IDMap, error)

Load reads a Document from r, validates it, and writes the graph into db. Returns a mapping from document node IDs to database IDs.

func WriteGraph

func WriteGraph(ctx context.Context, db graph.Database, g *Graph) (IDMap, error)

WriteGraph writes the nodes and edges of g into db. Returns a mapping from document node IDs to database IDs.

func WriteGraphTx

func WriteGraphTx(tx graph.Transaction, g *Graph) (IDMap, error)

WriteGraphTx writes the nodes and edges of g using an existing transaction. This is useful for creating fixture data that will be rolled back.

type Node

type Node struct {
	ID         string         `json:"id"`
	Kinds      []string       `json:"kinds"`
	Properties map[string]any `json:"properties,omitempty"`
}

Node represents a graph node with a string ID, one or more kind labels, and arbitrary properties.

Jump to

Keyboard shortcuts

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