graphgorm

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

@index GORM persistence adapter for git-diff change-risk analysis.

@index GORM read adapter for documentation generation and lint facts.

@index GORM persistence adapter for atomic stored-flow rebuilds.

@index GORM persistence adapter for predefined analysis graph queries.

@index GORM read models for MCP graph, context, namespace, and change surfaces.

@index GORM graph statistics adapter for operator and protocol read surfaces.

@index GORM-based graph repository that manages CRUD operations and transactions for nodes, edges, and annotations.

@index GORM unit-of-work adapter for atomic graph and derived search updates.

@index GORM read adapter for eager and lazy built-in Wiki tree construction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SearchWriterFactory

type SearchWriterFactory func(tx *gorm.DB) ingest.SearchWriter

SearchWriterFactory binds a search writer to the active GORM transaction. @intent construct derived-state persistence with the same transaction handle as graph persistence.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the GORM-backed GraphStore implementation. @intent implement the graph repository contract through a GORM DB handle.

func New

func New(db *gorm.DB) *Store

New creates a repository wrapping a GORM DB. @intent initialize the GraphStore implementation with the injected DB handle.

func (*Store) AffectedFlowsPage

func (s *Store) AffectedFlowsPage(ctx context.Context, changedNodeIDs []uint, limit, offset int) ([]analyze.AffectedFlow, bool, error)

@intent map changed nodes to one deterministic page of namespace-scoped stored flows.

func (*Store) Annotations

func (s *Store) Annotations(ctx context.Context, ids []uint) (map[uint]*graph.Annotation, error)

@intent batch-load Wiki annotations with deterministic tag ordering.

func (*Store) AutoMigrate

func (s *Store) AutoMigrate() error

AutoMigrate creates or updates the graph repository schema. @intent prepare the GORM model tables required for graph persistence. @sideEffect may modify the database schema.

func (*Store) CCGRefExists

func (s *Store) CCGRefExists(ctx context.Context, ref reference.Ref) (bool, error)

@intent validate parsed cross-namespace ccg references against graph path and symbol semantics.

func (*Store) CallEdges

func (s *Store) CallEdges(ctx context.Context, anchorID uint, peerIDs []uint, direction analyze.EdgeDirection) (map[uint]graph.Edge, error)

@intent select the strongest call evidence edge for each requested peer node.

func (*Store) CreateFlow

func (s *Store) CreateFlow(ctx context.Context, flow *graph.Flow) error

CreateFlow persists one flow and its ordered memberships through the active transaction. @intent store traced flow aggregates while keeping generated IDs visible to application results. @sideEffect inserts a flow row and zero or more flow-membership rows. @mutates flow.ID and each flow.Members item FlowID.

func (*Store) DeleteEdgesByFile

func (s *Store) DeleteEdgesByFile(ctx context.Context, filePath string) error

DeleteEdgesByFile removes edges generated from a file. @intent selectively clean existing relationships during file-scoped updates. @sideEffect deletes matching file_path records from the edges table.

func (*Store) DeleteFlows

func (s *Store) DeleteFlows(ctx context.Context) error

DeleteFlows removes all stored flows and memberships in the active namespace. @intent clear stale flow state before a transaction-scoped rebuild. @sideEffect deletes namespace-owned flow and flow-membership rows.

func (*Store) DeleteGraph

func (s *Store) DeleteGraph(ctx context.Context) error

DeleteGraph removes the entire graph state for the current namespace. @intent replace namespace-scoped state before a full rebuild or include_paths rebuild. @sideEffect deletes all nodes, edges, annotations, and doc_tags in the namespace.

func (*Store) DeleteNodesByFile

func (s *Store) DeleteNodesByFile(ctx context.Context, filePath string) error

DeleteNodesByFile removes nodes in a file and their related data. @intent clean out prior nodes, edges, and annotations before reparsing a file. @sideEffect deletes related records from the nodes, edges, annotations, and doc_tags tables. @domainRule connected edges and annotations must also be removed when deleting a file.

func (*Store) DeletePackageSemanticEdges

func (s *Store) DeletePackageSemanticEdges(ctx context.Context, anchors []string) error

DeletePackageSemanticEdges removes synthesized package-level implementation edges for anchor files. @intent replace stale package semantic relationships without exposing persistence queries to the application layer. @sideEffect deletes namespace-scoped edge rows matching the supplied anchors. @domainRule only synthesized implements edges, identified by line zero, are eligible for deletion.

func (*Store) FileSymbols

func (s *Store) FileSymbols(ctx context.Context, filePath string, kinds []graph.NodeKind) ([]graph.Node, error)

@intent load stable symbol children for one lazy Wiki file node.

func (*Store) FindFlowEntrypoints

func (s *Store) FindFlowEntrypoints(ctx context.Context) ([]graph.Node, error)

FindFlowEntrypoints returns function/test nodes with no inbound call-kind edge. @intent provide deterministic namespace-scoped entrypoints for stored-flow rebuild policy. @domainRule inbound detection includes every kind returned by graph.CallEdgeKinds.

func (*Store) FlowsPage

func (s *Store) FlowsPage(ctx context.Context, sortBy string, limit, offset int) ([]analyze.FlowSummary, bool, error)

@intent load one stable namespace-scoped stored-flow page with member counts.

func (*Store) GetAnnotation

func (s *Store) GetAnnotation(ctx context.Context, nodeID uint) (*graph.Annotation, error)

GetAnnotation retrieves the annotation attached to a node ID. @intent load a node's structured comment and tags together for search and display. @return returns nil when no annotation exists.

func (*Store) GetEdgesFrom

func (s *Store) GetEdgesFrom(ctx context.Context, nodeID uint) ([]graph.Edge, error)

GetEdgesFrom retrieves outgoing edges from a node. @intent load outbound relationships for a specific declaration.

func (*Store) GetEdgesFromNodes

func (s *Store) GetEdgesFromNodes(ctx context.Context, nodeIDs []uint) ([]graph.Edge, error)

GetEdgesFromNodes retrieves outgoing edges from multiple nodes. @intent load outbound relationships for multiple declarations in one call. @return returns a nil slice when nodeIDs is empty.

func (*Store) GetEdgesTo

func (s *Store) GetEdgesTo(ctx context.Context, nodeID uint) ([]graph.Edge, error)

GetEdgesTo retrieves incoming edges to a node. @intent load inbound relationships for a specific declaration.

func (*Store) GetEdgesToNodes

func (s *Store) GetEdgesToNodes(ctx context.Context, nodeIDs []uint) ([]graph.Edge, error)

GetEdgesToNodes retrieves incoming edges to multiple nodes. @intent load inbound relationships for multiple declarations in one call. @return returns a nil slice when nodeIDs is empty.

func (*Store) GetFileNodesByPathSuffix

func (s *Store) GetFileNodesByPathSuffix(ctx context.Context, suffix string) ([]graph.Node, error)

GetFileNodesByPathSuffix finds file nodes whose directory matches an import-path suffix. @intent let import edge resolution bind repo-local import paths back to stored file nodes.

func (*Store) GetNode

func (s *Store) GetNode(ctx context.Context, qualifiedName string) (*graph.Node, error)

GetNode retrieves a single node by qualified name. @intent find one node by the declaration's qualified name. @return returns nil when no node exists.

func (*Store) GetNodeByID

func (s *Store) GetNodeByID(ctx context.Context, id uint) (*graph.Node, error)

GetNodeByID retrieves a single node by primary key. @intent find one node by its internal identifier. @return returns nil when no node exists.

func (*Store) GetNodesByFile

func (s *Store) GetNodesByFile(ctx context.Context, filePath string) ([]graph.Node, error)

GetNodesByFile retrieves nodes belonging to a file path. @intent load declarations parsed from a specific source file.

func (*Store) GetNodesByFiles

func (s *Store) GetNodesByFiles(ctx context.Context, filePaths []string) (map[string][]graph.Node, error)

GetNodesByFiles retrieves nodes from multiple files grouped by file path. @intent return declarations for a file set grouped by path. @return returns a map whose keys are file paths and values are the nodes in each file.

func (*Store) GetNodesByIDs

func (s *Store) GetNodesByIDs(ctx context.Context, ids []uint) ([]graph.Node, error)

GetNodesByIDs retrieves nodes matching the provided ID list. @intent load multiple nodes at once by internal identifier. @return returns a nil slice when ids is empty.

func (*Store) GetNodesByQualifiedNames

func (s *Store) GetNodesByQualifiedNames(ctx context.Context, names []string) (map[string][]graph.Node, error)

GetNodesByQualifiedNames loads a set of names into a node map. @intent build a fast lookup map for qualified-name-based reference resolution. @return returns a map keyed by QualifiedName, with slices containing all nodes for each name.

func (*Store) GraphStatistics

func (s *Store) GraphStatistics(ctx context.Context) (analyze.GraphStatistics, error)

GraphStatistics loads totals and grouped distributions for the active namespace. @intent implement the application statistics port while preserving namespace filtering and aggregate semantics.

func (*Store) GraphView

func (s *Store) GraphView(ctx context.Context, limit int, edgeKinds []graph.EdgeKind) (wiki.GraphView, error)

GraphView loads a bounded stable node set and only edges contained within it. @intent implement the Wiki force-graph read port with deterministic ordering and limits.

func (*Store) HasSymbol

func (s *Store) HasSymbol(ctx context.Context, filePath string, kinds []graph.NodeKind) (bool, error)

@intent answer whether a lazy file node has expandable symbol children.

func (*Store) ListFileNodes

func (s *Store) ListFileNodes(ctx context.Context) ([]graph.Node, error)

ListFileNodes returns the minimal persisted state used to compare source files during an update. @intent expose namespace-scoped file identity and hash state without leaking the database handle.

func (*Store) Namespaces

func (s *Store) Namespaces(ctx context.Context) ([]string, error)

Namespaces returns distinct stored namespaces in stable order. @intent implement Wiki namespace discovery without exposing persistence to HTTP.

func (*Store) NamespacesPage

func (s *Store) NamespacesPage(ctx context.Context, limit, offset int) ([]analyze.NamespaceSummary, bool, error)

@intent load one stable global namespace page with node counts.

func (*Store) NavigationNodes

func (s *Store) NavigationNodes(ctx context.Context, kinds []graph.NodeKind) ([]graph.Node, error)

@intent load the stable graph snapshot from which the eager Wiki hierarchy is derived.

func (*Store) NodesByExactName

func (s *Store) NodesByExactName(ctx context.Context, name string, limit int) ([]graph.Node, error)

NodesByExactName loads deterministic namespace-scoped short-name matches. @intent support exact-name fallback suggestions through the analysis repository.

func (*Store) NodesByFile

func (s *Store) NodesByFile(ctx context.Context, filePath string) ([]graph.Node, error)

NodesByFile loads all namespace-scoped nodes belonging to one file. @intent supply file-summary inputs without exposing database filtering to app policy.

func (*Store) NodesByFiles

func (s *Store) NodesByFiles(ctx context.Context, filePaths []string) ([]graph.Node, error)

NodesByFiles loads deterministic namespace-scoped graph nodes for changed files. @intent supply diff-overlap inputs without exposing database filters to change policy.

func (*Store) OutgoingDocEdges

func (s *Store) OutgoingDocEdges(ctx context.Context, namespace string, ids []uint) (map[uint][]graph.Edge, error)

@intent load call/import relationships rendered beneath symbol documentation.

func (*Store) OutgoingEdgeCounts

func (s *Store) OutgoingEdgeCounts(ctx context.Context, nodeIDs []uint) (map[uint]int64, error)

OutgoingEdgeCounts returns namespace-scoped outgoing edge counts keyed by source node ID. @intent provide risk-weight inputs through one grouped persistence query.

func (*Store) PathNodes

func (s *Store) PathNodes(ctx context.Context, folderPath string, kinds []graph.NodeKind) ([]graph.Node, error)

@intent load stable path-bearing candidates below one lazy Wiki folder or package.

func (*Store) QualifiedNameExists

func (s *Store) QualifiedNameExists(ctx context.Context, namespace, name string) (bool, error)

@intent validate local @see targets within the active docs namespace.

func (*Store) RelatedNodes

RelatedNodes loads one deterministic distinct relationship page and its total count. @intent implement namespace-scoped relationship joins behind the analysis query repository.

func (*Store) ResolveReference

func (s *Store) ResolveReference(ctx context.Context, ref *reference.Ref) (*graph.Node, error)

ResolveReference finds the first deterministic graph node matching a parsed CCG reference. @intent resolve Wiki reference navigation while keeping GORM filtering and preload behavior in the outbound adapter.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context, namespace string, kinds []graph.NodeKind) (docsapp.Snapshot, error)

@intent load documentable nodes and their annotations from one namespace.

func (*Store) StoredNode

func (s *Store) StoredNode(ctx context.Context, kind graph.NodeKind, filePath string) (*graph.Node, error)

@intent resolve one stored package or file used as a lazy Wiki root.

func (*Store) SymbolNode

func (s *Store) SymbolNode(ctx context.Context, qualifiedName string, kinds []graph.NodeKind) (*graph.Node, error)

@intent resolve the first deterministic symbol match used by direct lazy navigation.

func (*Store) TopCommunities

func (s *Store) TopCommunities(ctx context.Context, limit int) ([]analyze.NamedCount, error)

@intent rank namespace communities by stored membership count.

func (*Store) TopFlows

func (s *Store) TopFlows(ctx context.Context, limit int) ([]analyze.NamedCount, error)

@intent rank namespace flows by stored membership count.

func (*Store) UntestedCount

func (s *Store) UntestedCount(ctx context.Context, nodeIDs []uint) (int, error)

@intent count requested nodes without a namespace-scoped tested_by edge.

func (*Store) UpsertAnnotation

func (s *Store) UpsertAnnotation(ctx context.Context, ann *graph.Annotation) error

UpsertAnnotation stores a node's annotation and tags. @intent replace structured comments for each node with the latest state. @sideEffect performs inserts, updates, and deletes on the annotations and doc_tags tables. @mutates may overwrite ann.ID with the existing record ID. @domainRule only one annotation must be kept per node_id.

func (*Store) UpsertEdges

func (s *Store) UpsertEdges(ctx context.Context, edges []graph.Edge) error

UpsertEdges stores a batch of edges keyed by fingerprint. @intent apply graph relationships in bulk without duplicates. @sideEffect performs batch inserts on the edges table. @domainRule edges with the same fingerprint must be stored only once.

func (*Store) UpsertNodes

func (s *Store) UpsertNodes(ctx context.Context, nodes []graph.Node) error

UpsertNodes stores a batch of nodes keyed by qualified_name. @intent apply parsed result nodes in bulk without creating duplicates. @sideEffect performs batch inserts and updates on the nodes table. @requires nodes must have a non-empty QualifiedName. @ensures existing nodes with the same qualified_name are updated with the latest metadata.

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(store ingest.GraphStore) error) error

WithTx executes the given function inside the same transaction. @intent allow multiple repository operations to run atomically as one unit. @sideEffect starts a database transaction and commits or rolls it back. @ensures commits the transaction when fn returns a nil error.

func (*Store) WithTxDB

func (s *Store) WithTxDB(ctx context.Context, fn func(ingest.GraphStore, *gorm.DB) error) error

WithTxDB passes the transaction DB handle together with the repository. @intent let graph persistence and DB-backed derived-state updates share a single transaction. @sideEffect starts a database transaction and commits or rolls it back.

func (*Store) WithinFlowRebuild

func (s *Store) WithinFlowRebuild(ctx context.Context, fn func(analyzeapp.FlowRebuildStore) error) error

WithinFlowRebuild executes stored-flow replacement against one transaction-scoped store. @intent implement the analysis flow unit of work without exposing GORM to application policy. @sideEffect starts a transaction and commits or rolls back namespace-scoped flow changes.

type UnitOfWork

type UnitOfWork struct {
	// contains filtered or unexported fields
}

UnitOfWork implements the ingest atomicity boundary with GORM transactions. @intent coordinate graph and search writes without exposing GORM to application policy.

func NewUnitOfWork

func NewUnitOfWork(db *gorm.DB, newSearchWriter SearchWriterFactory) *UnitOfWork

NewUnitOfWork constructs a GORM-backed ingest unit of work. @intent inject the database transaction owner and transaction-scoped search writer factory.

func (*UnitOfWork) WithinTransaction

func (u *UnitOfWork) WithinTransaction(ctx context.Context, fn func(ingest.Transaction) error) error

WithinTransaction executes graph and search work against one GORM transaction. @intent commit graph and derived search state together or roll both back on any callback error. @sideEffect starts a database transaction and commits or rolls it back. @ensures the callback is not invoked unless both transaction capabilities are available.

Jump to

Keyboard shortcuts

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