models

package
v0.30.38 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RefTypeValue is the "type" field value that marks a map as a REF object.
	RefTypeValue = "REF"

	// SchemaFormatREF is the JSON Schema "format" value that marks a field as
	// a REF reference in xolu schemas. Used by DeriveAdaptedTableSpecFrom and
	// the validation layer.
	SchemaFormatREF = "ref"
)

REF type and schema constants. These are the single source of truth for REF field naming across the codebase. All packages that need to identify, construct, or format a REF value must use these constants rather than embedding the string literals directly.

Variables

View Source
var ErrDuplicateEdgeTarget = errors.New("entity has two REF fields pointing to the same target")

ErrDuplicateEdgeTarget is returned by ExtractEntityEdges when two or more fields in the same entity document reference the same target (entity, id) pair. In xolu's graph model each ordered node pair may carry at most one labelled edge. A document that produces two edges to the same target is malformed and must be rejected at write time.

Functions

This section is empty.

Types

type Entity

type Entity struct {
	ID   int                    `json:"id"`
	Type string                 `json:"type,omitempty"`
	Data map[string]interface{} `json:"-"`
}

Entity represents a stored entity with its data

func (*Entity) MarshalJSON

func (e *Entity) MarshalJSON() ([]byte, error)

MarshalJSON implements custom marshaling for Entity

func (*Entity) UnmarshalJSON

func (e *Entity) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling for Entity

type EntityEdge

type EntityEdge struct {
	TargetEntity string
	TargetID     int
	Relationship string
}

EntityEdge is a raw graph edge extracted from entity data before any tenant-scoping or node-ID formatting is applied. It holds the target entity type, target ID, and the relationship name (the field key that carried the REF value in the source document).

This is the canonical intermediate representation shared by all callers that need to extract graph edges from entity data:

  • storage.SQLiteStore.syncGraphEdges (writes to tenant graph_tXXXX table)
  • server.Server.updateGraph (writes to in-memory graph)
  • any future backend that derives edges from entity JSON

Keeping a single extraction function here ensures that a change to edge semantics (e.g. handling a new REF variant) is made in one place and automatically applies to both the durable edge table and the in-memory cache.

func ExtractEntityEdges

func ExtractEntityEdges(data map[string]interface{}) ([]EntityEdge, error)

ExtractEntityEdges returns all graph edges implied by the REF fields in data. It iterates every key in data (skipping "id"), calls ExtractRefs on each value, and converts valid references to EntityEdge values.

This is the single source of truth for "which fields in an entity document become graph edges". Both the SQLite storage layer (syncGraphEdges) and the server layer (updateGraph) must call this function rather than inlining their own ExtractRefs loops, so that the two pipelines are structurally guaranteed to agree.

Returns ErrDuplicateEdgeTarget if two fields in data reference the same (entity, id) target. In xolu's graph model each ordered node pair carries at most one labelled edge; a document violating this is malformed.

type ErrorResponse

type ErrorResponse struct {
	Error struct {
		Code    string `json:"code"`
		Message string `json:"message"`
		Status  int    `json:"status"`
	} `json:"error"`
}

ErrorResponse represents an API error response

type GraphEdge

type GraphEdge struct {
	From         string `json:"from"`
	To           string `json:"to"`
	Relationship string `json:"relationship"`
}

GraphEdge represents an edge in the graph

type GraphNode

type GraphNode struct {
	ID         string                 `json:"id"`
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
}

GraphNode represents a node in the graph

type PagedResponse

type PagedResponse struct {
	Data       interface{} `json:"data"`
	Pagination struct {
		Page       int `json:"page"`
		PerPage    int `json:"per_page"`
		TotalItems int `json:"total_items"`
		TotalPages int `json:"total_pages"`
	} `json:"pagination"`
	Links map[string]string `json:"links,omitempty"`
}

PagedResponse represents a paginated response

type PaginationParams

type PaginationParams struct {
	Page    int `json:"page"`
	PerPage int `json:"per_page"`
}

PaginationParams represents pagination parameters

type PathInfo

type PathInfo struct {
	From   string        `json:"from"`
	To     string        `json:"to"`
	Length int           `json:"length"`
	Path   []interface{} `json:"path"`
}

PathInfo represents a path between two nodes

type Query

type Query struct {
	ID          string                 `json:"id"`
	QueryString string                 `json:"query"`
	Status      string                 `json:"status"` // pending, running, completed, failed
	Result      interface{}            `json:"result,omitempty"`
	Error       string                 `json:"error,omitempty"`
	Stats       QueryStats             `json:"stats"`
	ParsedQuery map[string]interface{} `json:"parsed_query,omitempty"`
}

Query represents a stored query with its execution state

type QueryStats

type QueryStats struct {
	StartTime time.Time              `json:"start_time"`
	EndTime   time.Time              `json:"end_time,omitempty"`
	Duration  float64                `json:"duration,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

QueryStats tracks query execution statistics

type Reference

type Reference struct {
	Type   string `json:"type"`
	Entity string `json:"entity"`
	ID     int64  `json:"id"`
}

Reference represents a reference to another entity

func ExtractRefs

func ExtractRefs(v interface{}) []*Reference

ExtractRefs returns all REF values from a field value as typed References. It handles both a single REF map (the common case from @REF) and a []interface{} slice of REF maps (from @REFS). TSREF values are silently excluded — timeseries links are resolved at query time and must not become graph edges. Any non-REF value returns nil.

This is the single point of containment for the map[string]interface{} type-switching that would otherwise be scattered across syncGraphEdges, UpdateFromEntityForTenant, and any future callers that need to walk entity fields looking for graph-indexable references.

func IsReference

func IsReference(v interface{}) (*Reference, bool)

IsReference checks if a value is a reference

func NewReference

func NewReference(entity string, id int64) *Reference

NewReference constructs a Reference from an entity name and integer ID. Use ToMap to obtain the map[string]interface{} form required for JSON storage.

func (*Reference) ToMap

func (r *Reference) ToMap() map[string]interface{}

ToMap returns the canonical map representation of this Reference as stored in entity JSON. The shape matches what json.Unmarshal produces on read-back, ensuring round-trip consistency. Callers building REF values for storage should use this rather than constructing raw maps by hand.

type ResourceResponse

type ResourceResponse struct {
	Type  string      `json:"type"`
	ID    string      `json:"id,omitempty"`
	Data  interface{} `json:"data"`
	Links interface{} `json:"links,omitempty"`
	Meta  interface{} `json:"meta,omitempty"`
}

ResourceResponse represents a resource-based response

type SortParam

type SortParam struct {
	Field string `json:"field"`
	Order string `json:"order"` // asc or desc
}

SortParam represents a sort parameter

type SuccessResponse

type SuccessResponse struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

SuccessResponse represents a generic success response

type TSReference

type TSReference struct {
	Type     string   `json:"type"`
	Timeline int      `json:"timeline"`
	Dims     []uint64 `json:"dims"`
}

TSReference represents a timeseries link stored on a document entity. It is the typed counterpart of the {"type":"TSREF",...} map produced by @TIMESERIES / @TS in OQL INSERT statements.

TSREFs are intentionally excluded from graph edge indexing — they point to a timeseries partition, not to another entity node. syncGraphEdges must not create graph edges for TSREF fields.

func IsTSReference

func IsTSReference(v interface{}) (*TSReference, bool)

IsTSReference checks if a value is a timeseries reference map.

func NewTSReference

func NewTSReference(timeline int, dims []uint64) *TSReference

NewTSReference constructs a TSReference.

func (*TSReference) ToMap

func (r *TSReference) ToMap() map[string]interface{}

ToMap returns the canonical map representation of this TSReference for JSON storage, mirroring the shape produced by json.Unmarshal on read-back.

Jump to

Keyboard shortcuts

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