Documentation
¶
Index ¶
- Variables
- func ListTemplates() map[string][]*Template
- type Builder
- func (b *Builder) And(condition string) *Builder
- func (b *Builder) Build() (string, map[string]any, error)
- func (b *Builder) Create(pattern string) *Builder
- func (b *Builder) Delete(nodes string) *Builder
- func (b *Builder) DetachDelete(nodes string) *Builder
- func (b *Builder) Limit(count int) *Builder
- func (b *Builder) Match(pattern string) *Builder
- func (b *Builder) Merge(pattern string) *Builder
- func (b *Builder) OptionalMatch(pattern string) *Builder
- func (b *Builder) Or(condition string) *Builder
- func (b *Builder) OrderBy(fields string) *Builder
- func (b *Builder) ProjectFilter(projectID core.ID) *Builder
- func (b *Builder) Return(fields string) *Builder
- func (b *Builder) Set(assignments string) *Builder
- func (b *Builder) SetParameter(name string, value any) *Builder
- func (b *Builder) SetParameters(params map[string]any) *Builder
- func (b *Builder) Skip(count int) *Builder
- func (b *Builder) String() string
- func (b *Builder) Where(condition string) *Builder
- func (b *Builder) With(fields string) *Builder
- type ExportFormat
- type ExportOptions
- type ExportResult
- type Exporter
- type HighLevelBuilder
- func (hlb *HighLevelBuilder) CountNodesByType(projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) CountRelationshipsByType(projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindCircularDependencies(projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindComplexFunctions(projectID core.ID, minComplexity int) *Builder
- func (hlb *HighLevelBuilder) FindDependencies(nodeID core.ID, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindDependents(nodeID core.ID, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindInterfaceImplementations(projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindMostCalledFunctions(projectID core.ID, limit int) *Builder
- func (hlb *HighLevelBuilder) FindNodesByName(namePattern string, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindNodesByType(nodeType core.NodeType, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindPath(fromID, toID core.ID, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindRelationshipsByType(relType core.RelationType, projectID core.ID) *Builder
- func (hlb *HighLevelBuilder) FindUnusedFunctions(projectID core.ID) *Builder
- type ResultProcessor
- func (rp *ResultProcessor) Aggregate(results []map[string]any, groupKey string, ...) []map[string]any
- func (rp *ResultProcessor) Filter(results []map[string]any, predicate func(map[string]any) bool) []map[string]any
- func (rp *ResultProcessor) Flatten(results []map[string]any, separator string) []map[string]any
- func (rp *ResultProcessor) SortBy(results []map[string]any, field string, ascending bool) []map[string]any
- func (rp *ResultProcessor) Transform(results []map[string]any, transformer func(map[string]any) map[string]any) []map[string]any
- type Template
Constants ¶
This section is empty.
Variables ¶
var CommonTemplates = map[string]*Template{ "project_overview": { Name: "Project Overview", Description: "Get basic statistics about a project", Category: "overview", Query: `MATCH (n) WHERE n.project_id = $project_id RETURN labels(n)[0] as node_type, count(n) as count ORDER BY count DESC`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "project_files": { Name: "List Project Files", Description: "List all files in a project with their package information", Category: "overview", Query: `MATCH (f:File) WHERE f.project_id = $project_id RETURN f.path as file_path, f.name as file_name, f.package as package_name ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "project_packages": { Name: "List Project Packages", Description: "List all packages in a project with file counts", Category: "overview", Query: `MATCH (f:File) WHERE f.project_id = $project_id RETURN f.package as package_name, count(f) as file_count ORDER BY file_count DESC, package_name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "functions_by_package": { Name: "Functions by Package", Description: "List all functions grouped by package", Category: "functions", Query: `MATCH (f:Function) WHERE f.project_id = $project_id RETURN f.package as package_name, f.name as function_name, f.signature as signature, f.is_exported as is_exported ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "exported_functions": { Name: "Exported Functions", Description: "List all exported functions in a project", Category: "functions", Query: `MATCH (f:Function) WHERE f.project_id = $project_id AND f.is_exported = true RETURN f.package as package_name, f.name as function_name, f.signature as signature ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "function_complexity": { Name: "Function Complexity", Description: "List functions ordered by complexity (line count)", Category: "functions", Query: `MATCH (f:Function) WHERE f.project_id = $project_id WITH f, (f.line_end - f.line_start) as complexity RETURN f.package as package_name, f.name as function_name, complexity, f.signature as signature ORDER BY complexity DESC LIMIT 20`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "package_dependencies": { Name: "Package Dependencies", Description: "Show dependencies between packages", Category: "dependencies", Query: `MATCH (f1:File)-[:DEPENDS_ON]->(f2:File) WHERE f1.project_id = $project_id RETURN DISTINCT f1.package as from_package, f2.package as to_package ORDER BY from_package, to_package`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "external_dependencies": { Name: "External Dependencies", Description: "List external package imports", Category: "dependencies", Query: `MATCH (i:Import) WHERE i.project_id = $project_id AND NOT i.path STARTS WITH "." RETURN DISTINCT i.path as external_package, count(*) as usage_count ORDER BY usage_count DESC, external_package`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "dependency_graph": { Name: "Dependency Graph", Description: "Full dependency graph with relationships", Category: "dependencies", Query: `MATCH (f1:File)-[r:DEPENDS_ON]->(f2:File) WHERE f1.project_id = $project_id RETURN f1.path as from_file, f2.path as to_file, type(r) as relationship_type`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "interface_implementations": { Name: "Interface Implementations", Description: "List all interfaces and their implementations", Category: "types", Query: `MATCH (s:Struct)-[:IMPLEMENTS]->(i:Interface) WHERE s.project_id = $project_id RETURN i.package as interface_package, i.name as interface_name, s.package as struct_package, s.name as struct_name ORDER BY i.name, s.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "unimplemented_interfaces": { Name: "Unimplemented Interfaces", Description: "Find interfaces with no implementations", Category: "types", Query: `MATCH (i:Interface) WHERE i.project_id = $project_id AND NOT EXISTS { MATCH (s:Struct)-[:IMPLEMENTS]->(i) } RETURN i.package as package_name, i.name as interface_name ORDER BY i.package, i.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "struct_methods": { Name: "Struct Methods", Description: "List all structs and their methods", Category: "types", Query: `MATCH (s:Struct)-[:HAS_METHOD]->(m:Function) WHERE s.project_id = $project_id RETURN s.package as struct_package, s.name as struct_name, m.name as method_name, m.signature as method_signature ORDER BY s.name, m.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "function_calls": { Name: "Function Call Relationships", Description: "Show which functions call which other functions", Category: "calls", Query: `MATCH (f1:Function)-[:CALLS]->(f2:Function) WHERE f1.project_id = $project_id RETURN f1.package as caller_package, f1.name as caller_name, f2.package as callee_package, f2.name as callee_name ORDER BY caller_package, caller_name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "most_called_functions": { Name: "Most Called Functions", Description: "Functions ordered by how often they are called", Category: "calls", Query: `MATCH (f:Function)<-[:CALLS]-() WHERE f.project_id = $project_id RETURN f.package as package_name, f.name as function_name, count(*) as call_count, f.signature as signature ORDER BY call_count DESC LIMIT 20`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "unused_functions": { Name: "Unused Functions", Description: "Functions that are never called (potential dead code)", Category: "calls", Query: `MATCH (f:Function) WHERE f.project_id = $project_id AND NOT EXISTS { MATCH ()-[:CALLS]->(f) } AND f.name <> "main" AND f.name <> "init" RETURN f.package as package_name, f.name as function_name, f.signature as signature ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", }, }, "find_function": { Name: "Find Function by Name", Description: "Search for functions by name (case-insensitive)", Category: "search", Query: `MATCH (f:Function) WHERE f.project_id = $project_id AND toLower(f.name) CONTAINS toLower($function_name) RETURN f.package as package_name, f.name as function_name, f.signature as signature, f.is_exported as is_exported ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", "function_name": "string - Function name to search for", }, }, "find_struct": { Name: "Find Struct by Name", Description: "Search for structs by name (case-insensitive)", Category: "search", Query: `MATCH (s:Struct) WHERE s.project_id = $project_id AND toLower(s.name) CONTAINS toLower($struct_name) RETURN s.package as package_name, s.name as struct_name, s.is_exported as is_exported ORDER BY s.package, s.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", "struct_name": "string - Struct name to search for", }, }, "find_interface": { Name: "Find Interface by Name", Description: "Search for interfaces by name (case-insensitive)", Category: "search", Query: `MATCH (i:Interface) WHERE i.project_id = $project_id AND toLower(i.name) CONTAINS toLower($interface_name) RETURN i.package as package_name, i.name as interface_name, i.is_exported as is_exported ORDER BY i.package, i.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", "interface_name": "string - Interface name to search for", }, }, "search_code": { Name: "Search in Code", Description: "Search for text patterns in function signatures", Category: "search", Query: `MATCH (f:Function) WHERE f.project_id = $project_id AND toLower(f.signature) CONTAINS toLower($search_term) RETURN f.package as package_name, f.name as function_name, f.signature as signature ORDER BY f.package, f.name`, Parameters: map[string]string{ "project_id": "string - The project identifier", "search_term": "string - Text to search for in function signatures", }, }, }
CommonTemplates contains frequently used query templates
Functions ¶
func ListTemplates ¶
ListTemplates returns all available templates grouped by category
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent interface for building Cypher queries
func (*Builder) DetachDelete ¶
DetachDelete adds a DETACH DELETE clause
func (*Builder) OptionalMatch ¶
OptionalMatch adds an OPTIONAL MATCH clause
func (*Builder) ProjectFilter ¶
ProjectFilter adds a project ID filter condition
func (*Builder) SetParameter ¶
SetParameter adds a parameter to the query
func (*Builder) SetParameters ¶
SetParameters adds multiple parameters to the query
type ExportFormat ¶
type ExportFormat string
ExportFormat represents the export format
const ( FormatJSON ExportFormat = "json" FormatCSV ExportFormat = "csv" FormatTSV ExportFormat = "tsv" )
type ExportOptions ¶
type ExportOptions struct {
Format ExportFormat `json:"format"`
Pretty bool `json:"pretty"` // For JSON: pretty formatting
Headers bool `json:"headers"` // For CSV/TSV: include headers
Delimiter string `json:"delimiter"` // For CSV/TSV: custom delimiter
NullValue string `json:"null_value"` // How to represent null values
BoolFormat string `json:"bool_format"` // "true/false" or "1/0"
DateFormat string `json:"date_format"` // Date formatting
IncludeNull bool `json:"include_null"` // Whether to include null fields in JSON
}
ExportOptions contains options for exporting query results
func DefaultExportOptions ¶
func DefaultExportOptions(format ExportFormat) *ExportOptions
DefaultExportOptions returns default export options
type ExportResult ¶
type ExportResult struct {
Format ExportFormat `json:"format"`
RowCount int `json:"row_count"`
ColumnCount int `json:"column_count"`
Size int64 `json:"size"`
Error string `json:"error,omitempty"`
}
ExportResult represents the result of an export operation
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
Exporter handles exporting query results to different formats
func NewExporter ¶
func NewExporter(options *ExportOptions) *Exporter
NewExporter creates a new exporter with the specified options
func (*Exporter) ExportWithMetadata ¶
func (e *Exporter) ExportWithMetadata(writer io.Writer, results []map[string]any) (*ExportResult, error)
ExportWithMetadata exports results and returns metadata about the export
type HighLevelBuilder ¶
type HighLevelBuilder struct{}
HighLevelBuilder provides high-level query building methods for common patterns
func NewHighLevelBuilder ¶
func NewHighLevelBuilder() *HighLevelBuilder
NewHighLevelBuilder creates a new high-level query builder
func (*HighLevelBuilder) CountNodesByType ¶
func (hlb *HighLevelBuilder) CountNodesByType(projectID core.ID) *Builder
CountNodesByType creates a query to count nodes by type
func (*HighLevelBuilder) CountRelationshipsByType ¶
func (hlb *HighLevelBuilder) CountRelationshipsByType(projectID core.ID) *Builder
CountRelationshipsByType creates a query to count relationships by type
func (*HighLevelBuilder) FindCircularDependencies ¶
func (hlb *HighLevelBuilder) FindCircularDependencies(projectID core.ID) *Builder
FindCircularDependencies creates a query to detect circular dependencies
func (*HighLevelBuilder) FindComplexFunctions ¶
func (hlb *HighLevelBuilder) FindComplexFunctions(projectID core.ID, minComplexity int) *Builder
FindComplexFunctions creates a query to find functions with high complexity
func (*HighLevelBuilder) FindDependencies ¶
FindDependencies creates a query to find dependencies for a specific node
func (*HighLevelBuilder) FindDependents ¶
FindDependents creates a query to find what depends on a specific node
func (*HighLevelBuilder) FindInterfaceImplementations ¶
func (hlb *HighLevelBuilder) FindInterfaceImplementations(projectID core.ID) *Builder
FindInterfaceImplementations creates a query to find interface implementations
func (*HighLevelBuilder) FindMostCalledFunctions ¶
func (hlb *HighLevelBuilder) FindMostCalledFunctions(projectID core.ID, limit int) *Builder
FindMostCalledFunctions creates a query to find the most called functions
func (*HighLevelBuilder) FindNodesByName ¶
func (hlb *HighLevelBuilder) FindNodesByName(namePattern string, projectID core.ID) *Builder
FindNodesByName creates a query to find nodes by name pattern
func (*HighLevelBuilder) FindNodesByType ¶
FindNodesByType creates a query to find nodes by type and project
func (*HighLevelBuilder) FindPath ¶
FindPath creates a query to find the shortest path between two nodes
func (*HighLevelBuilder) FindRelationshipsByType ¶
func (hlb *HighLevelBuilder) FindRelationshipsByType(relType core.RelationType, projectID core.ID) *Builder
FindRelationshipsByType creates a query to find relationships by type
func (*HighLevelBuilder) FindUnusedFunctions ¶
func (hlb *HighLevelBuilder) FindUnusedFunctions(projectID core.ID) *Builder
FindUnusedFunctions creates a query to find potentially unused functions
type ResultProcessor ¶
type ResultProcessor struct{}
ResultProcessor provides utilities for processing query results
func NewResultProcessor ¶
func NewResultProcessor() *ResultProcessor
NewResultProcessor creates a new result processor
func (*ResultProcessor) Aggregate ¶
func (rp *ResultProcessor) Aggregate( results []map[string]any, groupKey string, aggregator func([]map[string]any) map[string]any, ) []map[string]any
Aggregate aggregates results by grouping key
func (*ResultProcessor) Filter ¶
func (rp *ResultProcessor) Filter( results []map[string]any, predicate func(map[string]any) bool, ) []map[string]any
Filter filters results based on a predicate function
type Template ¶
type Template struct {
Name string `json:"name"`
Description string `json:"description"`
Query string `json:"query"`
Parameters map[string]string `json:"parameters"`
Category string `json:"category"`
}
Template represents a query template with parameters
func GetTemplate ¶
GetTemplate retrieves a template by name
func GetTemplatesByCategory ¶
GetTemplatesByCategory returns templates for a specific category
func (*Template) BuildQuery ¶
BuildQuery builds the final query with parameter substitution validation
func (*Template) GetParameterHelp ¶
GetParameterHelp returns help text for template parameters