dbmodel

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectValueType

func DetectValueType(value any) string

func Migrations

func Migrations(opts ...migration.SuiteOption) *migration.Suite

Migrations returns the migration suite to bootstrap the database.

func TypeEdgeFromEdge

func TypeEdgeFromEdge(e Edge) types.Edge

TypeEdgeFromEdge returns an api edge from a given db edge.

func TypeGraphFromGraph

func TypeGraphFromGraph(g Graph) *types.Graph

TypeGraphFromGraph returns an api graph from an api graph.

func TypeNodeFromNode

func TypeNodeFromNode(n Node) types.Node

TypeNodeFromNode returns an api type node from a db model type node.

Types

type Edge

type Edge struct {
	CreatedUTC     time.Time `db:"created_utc"`
	GraphID        uuid.UUID `db:"graph_id,pk"`
	UserID         uuid.UUID `db:"user_id,pk"`
	ParentID       uuid.UUID `db:"parent_id,pk"`
	ChildID        uuid.UUID `db:"child_id,pk"`
	ChildInputName string    `db:"child_input_name,pk"`
}

Edge represents a link between two nodes.

func EdgeFromType

func EdgeFromType(graph *Graph, e types.Edge) *Edge

EdgeFromType returns a db edge from a given api edge.

func (Edge) TableName

func (e Edge) TableName() string

TableName returns the mapped table name.

type Graph

type Graph struct {
	ID               uuid.UUID `db:"id,pk"`
	CreatedUTC       time.Time `db:"created_utc"`
	UpdatedUTC       time.Time `db:"updated_utc"`
	UserID           uuid.UUID `db:"user_id"`
	Label            string    `db:"label"`
	StabilizationNum uint64    `db:"stabilization_num"`
	ViewportX        float64   `db:"viewport_x"`
	ViewportY        float64   `db:"viewport_y"`
	ViewportZoom     float64   `db:"viewport_zoom"`
}

Graph is the root object for computations.

func GraphFromIncr

func GraphFromIncr(g *incr.Graph, vp types.Viewport) Graph

GraphFromIncr returns a db graph from an incremental graph.

func GraphFromType

func GraphFromType(g *types.Graph) *Graph

GraphFromType returns a db graph from an api graph.

func NewGraph

func NewGraph() *Graph

NewGraph returns a new, empty, graph.

func (Graph) TableName

func (g Graph) TableName() string

TableName returns the mapped table name.

type GraphLogs

type GraphLogs struct {
	GraphID          uuid.UUID `db:"graph_id,pk"`
	UserID           uuid.UUID `db:"user_id,pk"`
	StabilizationNum uint64    `db:"stabilization_num,pk"`
	CreatedUTC       time.Time `db:"created_utc"`
	Logs             string    `db:"logs"`
}

GraphLogs are log outputs for each stabilization run.

func (GraphLogs) TableName

func (gl GraphLogs) TableName() string

type GraphRecomputeHeap

type GraphRecomputeHeap struct {
	GraphID uuid.UUID `db:"graph_id,pk"`
	UserID  uuid.UUID `db:"user_id,pk"`
	NodeID  uuid.UUID `db:"node_id,pk"`
}

func (GraphRecomputeHeap) TableName

func (grh GraphRecomputeHeap) TableName() string

type Manager

type Manager struct {
	dbutil.BaseManager
}

func (Manager) DeleteEdge

func (m Manager) DeleteEdge(ctx context.Context, parentID, childID uuid.UUID, childInputName string) (err error)

func (Manager) DeleteGraph

func (m Manager) DeleteGraph(ctx context.Context, graphID uuid.UUID) (found bool, err error)

func (Manager) DeleteNode

func (m Manager) DeleteNode(ctx context.Context, nodeID uuid.UUID) (found bool, err error)

func (Manager) Deserialize

func (m Manager) Deserialize(ctx context.Context, graphID uuid.UUID, skipValues, skipRecomputeHeap bool) (output *types.GraphFull, err error)

func (Manager) Edges

func (m Manager) Edges(ctx context.Context, graphID uuid.UUID) (output []Edge, err error)

func (Manager) Graph

func (m Manager) Graph(ctx context.Context, id uuid.UUID) (output Graph, found bool, err error)

func (Manager) GraphActiveForUser

func (m Manager) GraphActiveForUser(ctx context.Context, userID uuid.UUID) (output Graph, found bool, err error)

func (Manager) GraphLogsLatest

func (m Manager) GraphLogsLatest(ctx context.Context, graphID uuid.UUID) (output GraphLogs, found bool, err error)

func (Manager) GraphsForUser

func (m Manager) GraphsForUser(ctx context.Context, userID uuid.UUID) (output []Graph, err error)

func (Manager) MarkNodeStale

func (m Manager) MarkNodeStale(ctx context.Context, graphID, userID, nodeID uuid.UUID) (found bool, err error)

func (Manager) Node

func (m Manager) Node(ctx context.Context, id uuid.UUID) (output Node, found bool, err error)

func (Manager) NodeValue

func (m Manager) NodeValue(ctx context.Context, graphID, nodeID uuid.UUID) (output NodeValue, found bool, err error)

func (Manager) NodeValues

func (m Manager) NodeValues(ctx context.Context, graphID uuid.UUID, nodeIDs ...uuid.UUID) (output []NodeValue, err error)

func (Manager) Nodes

func (m Manager) Nodes(ctx context.Context, graphID uuid.UUID) (output []Node, err error)

func (Manager) PatchGraph

func (m Manager) PatchGraph(ctx context.Context, graphID uuid.UUID, ps types.PatchSet) (found bool, err error)

func (Manager) PatchNode

func (m Manager) PatchNode(ctx context.Context, nodeID uuid.UUID, ps types.PatchSet) (bool, error)

func (Manager) PatchNodes

func (m Manager) PatchNodes(ctx context.Context, graphID uuid.UUID, ps types.PatchSet) error

func (Manager) RecomputeHeap

func (m Manager) RecomputeHeap(ctx context.Context, graphID uuid.UUID) (output []GraphRecomputeHeap, err error)

func (Manager) SetNodeHeights

func (m Manager) SetNodeHeights(ctx context.Context, graphID uuid.UUID, nodeHeights map[uuid.UUID]int) (err error)

func (Manager) SetNodeMetadata

func (m Manager) SetNodeMetadata(ctx context.Context, graphID uuid.UUID, nodeMetadata map[uuid.UUID]Node) (err error)

func (Manager) SetNodeValues

func (m Manager) SetNodeValues(ctx context.Context, graphID, userID uuid.UUID, values map[uuid.UUID]any) error

func (Manager) SetRecomputeHeap

func (m Manager) SetRecomputeHeap(ctx context.Context, graphID, userID uuid.UUID, nodeIDs ...uuid.UUID) (err error)

func (Manager) SetViewport

func (m Manager) SetViewport(ctx context.Context, graphID uuid.UUID, viewport types.Viewport) (err error)

func (Manager) TouchGraph

func (m Manager) TouchGraph(ctx context.Context, graphID uuid.UUID) (err error)

TouchGraph sets the updated time for the graph in the database.

The updated time is used to order the graph in lists, so this will push the graph to be the most recently updated graph in those lists.

func (Manager) UpdateGraphPostStabilization

func (m Manager) UpdateGraphPostStabilization(ctx context.Context, graphID uuid.UUID, stabilizationNum uint64) error

type Node

type Node struct {
	ID                        uuid.UUID  `db:"id,pk"`
	CreatedUTC                time.Time  `db:"created_utc"`
	UpdatedUTC                *time.Time `db:"updated_utc"`
	GraphID                   uuid.UUID  `db:"graph_id"`
	UserID                    uuid.UUID  `db:"user_id"`
	Label                     string     `db:"label"`
	SetAt                     uint64     `db:"set_at"`
	ChangedAt                 uint64     `db:"changed_at"`
	RecomputedAt              uint64     `db:"recomputed_at"`
	Valid                     bool       `db:"valid"`
	Always                    bool       `db:"always"`
	Observer                  bool       `db:"observer"`
	Height                    int        `db:"height"`
	HeightInRecomputeHeap     int        `db:"height_in_recompute_heap"`
	HeightInAdjustHeightsHeap int        `db:"height_in_adjust_heights_heap"`

	PositionX        float64  `db:"position_x"`
	PositionY        float64  `db:"position_y"`
	DisplayHeight    *float64 `db:"display_height"`
	DisplayWidth     *float64 `db:"display_width"`
	Collapsed        bool     `db:"collapsed"`
	NodeType         string   `db:"node_type"`
	InputType        string   `db:"input_type"`
	OutputType       string   `db:"output_type"`
	Watched          bool     `db:"watched"`
	WatchedCollapsed bool     `db:"watched_collapsed"`

	Expression string `db:"expression"`
}

Node is the main entity in a computation.

func NodeFromTypeNode

func NodeFromTypeNode(graphID uuid.UUID, userID uuid.UUID, n *types.Node) *Node

NodeFromTypeNode returns a db model node from a given api type node.

func (Node) TableName

func (n Node) TableName() string

type NodeValue

type NodeValue struct {
	GraphID   uuid.UUID `db:"graph_id,pk"`
	NodeID    uuid.UUID `db:"node_id,pk"`
	UserID    uuid.UUID `db:"user_id"`
	ValueType string    `db:"value_type"`
	Value     any       `db:"value,json"`
}

NodeValue is the current value for a given node in a graph.

func (NodeValue) ParsedValue

func (nv NodeValue) ParsedValue() (any, error)

ParsedValue returns the value according to the underlying type.

func (NodeValue) TableName

func (nv NodeValue) TableName() string

type Store

type Store struct {
	GraphID uuid.UUID
	UserID  uuid.UUID
	Model   *Manager
}

Store is a wrapper for a model manager that implements the graph store api against the database for a given graph by identifier.

func (Store) AddNode

func (s Store) AddNode(ctx context.Context, n *types.Node) (id incr.Identifier, err error)

func (Store) Edges

func (s Store) Edges(ctx context.Context) ([]types.Edge, error)

func (Store) Graph

func (s Store) Graph(ctx context.Context) (*types.Graph, error)

func (Store) LinkInput

func (s Store) LinkInput(ctx context.Context, te types.Edge) error

func (Store) Load

func (s Store) Load(ctx context.Context, graph *types.GraphFull) (id incr.Identifier, err error)

func (Store) Logs

func (s Store) Logs(ctx context.Context) (string, error)

func (Store) MarkNodeStale

func (s Store) MarkNodeStale(ctx context.Context, nodeID incr.Identifier) (found bool, err error)

func (Store) Node

func (s Store) Node(ctx context.Context, id incr.Identifier) (output types.Node, found bool, err error)

func (Store) NodeValue

func (s Store) NodeValue(ctx context.Context, id incr.Identifier) (any, bool, error)

func (Store) NodeValues

func (s Store) NodeValues(ctx context.Context, nodeIDs ...incr.Identifier) ([]types.NodeValue, error)

func (Store) Nodes

func (s Store) Nodes(ctx context.Context) ([]types.Node, error)

func (Store) PatchNode

func (s Store) PatchNode(ctx context.Context, id incr.Identifier, ps types.PatchSet) (found bool, err error)

func (Store) PatchNodeTable

func (s Store) PatchNodeTable(ctx context.Context, nodeID incr.Identifier, ops ...types.TableOp) (bool, error)

func (Store) PatchNodes

func (s Store) PatchNodes(ctx context.Context, ps types.PatchSet) (err error)

func (Store) RemoveNode

func (s Store) RemoveNode(ctx context.Context, id incr.Identifier) (found bool, err error)

func (Store) Save

func (s Store) Save(ctx context.Context) (*types.GraphFull, error)

func (Store) SetNodeValue

func (s Store) SetNodeValue(ctx context.Context, nodeID incr.Identifier, value any) (bool, error)

func (Store) SetViewport

func (s Store) SetViewport(ctx context.Context, viewport types.Viewport) error

func (Store) Stabilize

func (s Store) Stabilize(ctx context.Context, parallel bool) (stabilizationNum uint64, err error)

func (Store) UnlinkInput

func (s Store) UnlinkInput(ctx context.Context, te types.Edge) error

Jump to

Keyboard shortcuts

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