analyzer

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLargeOffsetThreshold = 1000

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

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

func New

func New(cfg Config) *Analyzer

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(ctx context.Context, input Input) (Report, error)

func (*Analyzer) Inspect added in v0.4.0

Inspect adapts the analyzer to the ORM query advisor interface.

type Config

type Config struct {
	Rules                []Rule
	LargeOffsetThreshold int
	Observability        orm.ObservabilityConfig
}

type Context

type Context struct {
	Query             ParsedQuery
	Table             *schema.Table
	Schema            *schema.Schema
	LargeOffsetThresh int
}

type Finding

type Finding struct {
	Code           string
	Rule           string
	Severity       Severity
	Title          string
	Details        string
	Recommendation string
	Table          string
	Columns        []string
}

type Input

type Input struct {
	SQL    string
	Table  string
	Schema *schema.Schema
}

type ParsedQuery

type ParsedQuery struct {
	SQL           string
	Kind          QueryKind
	Table         string
	WhereClause   string
	OrderByClause string
	WhereColumns  []string
	OrderByCols   []string
	Offset        int
	HasOffset     bool
	HasWhere      bool
	HasJoin       bool
}

func ParseSQL

func ParseSQL(sqlText string) (ParsedQuery, error)

type QueryKind

type QueryKind string
const (
	QueryKindUnknown QueryKind = "unknown"
	QueryKindSelect  QueryKind = "select"
	QueryKindUpdate  QueryKind = "update"
	QueryKindDelete  QueryKind = "delete"
	QueryKindInsert  QueryKind = "insert"
)

type Report

type Report struct {
	Table    string
	Kind     QueryKind
	SQL      string
	Findings []Finding
}

func (Report) Empty

func (r Report) Empty() bool

func (Report) String

func (r Report) String() string

type Rule

type Rule interface {
	Name() string
	Apply(context Context) []Finding
}

func DefaultRules

func DefaultRules() []Rule

type RuleInefficientOrderBy

type RuleInefficientOrderBy struct{}

func (RuleInefficientOrderBy) Apply

func (RuleInefficientOrderBy) Apply(ctx Context) []Finding

func (RuleInefficientOrderBy) Name

type RuleLargeOffset

type RuleLargeOffset struct{}

func (RuleLargeOffset) Apply

func (RuleLargeOffset) Apply(ctx Context) []Finding

func (RuleLargeOffset) Name

func (RuleLargeOffset) Name() string

type RuleMissingCompositeIndex

type RuleMissingCompositeIndex struct{}

func (RuleMissingCompositeIndex) Apply

func (RuleMissingCompositeIndex) Name

type RuleMissingIndex

type RuleMissingIndex struct{}

func (RuleMissingIndex) Apply

func (RuleMissingIndex) Apply(ctx Context) []Finding

func (RuleMissingIndex) Name

func (RuleMissingIndex) Name() string

type RuleMissingWhere

type RuleMissingWhere struct{}

func (RuleMissingWhere) Apply

func (RuleMissingWhere) Apply(ctx Context) []Finding

func (RuleMissingWhere) Name

func (RuleMissingWhere) Name() string

type RulePotentialFullTableScan

type RulePotentialFullTableScan struct{}

func (RulePotentialFullTableScan) Apply

func (RulePotentialFullTableScan) Name

type RuleSequentialScan

type RuleSequentialScan struct{}

func (RuleSequentialScan) Apply

func (RuleSequentialScan) Apply(ctx Context) []Finding

func (RuleSequentialScan) Name

func (RuleSequentialScan) Name() string

type Severity

type Severity string
const (
	SeverityInfo     Severity = "info"
	SeverityWarning  Severity = "warning"
	SeverityCritical Severity = "critical"
)

Jump to

Keyboard shortcuts

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