Documentation
¶
Overview ¶
Package parser provides statement metadata analysis for lock levels and transaction requirements.
Index ¶
- func ExtractStaticDDLFromDoBlock(doBlockSQL string) []string
- func FormatLockLevel(level types.LockLevel) string
- func IsValidPostgreSQLIdentifier(identifier string) bool
- func ParseMigration(content string, filename string) (*types.Migration, error)
- func ParseMigrationWithContext(ctx context.Context, content string, filename string) (*types.Migration, error)
- func SuggestIdentifierName(input string) string
- type ContextualKeywordChecker
- type ContextualNormalizer
- func (cn *ContextualNormalizer) BatchNormalize(identifiers []string) ([]string, []error)
- func (cn *ContextualNormalizer) CompareIdentifiers(id1, id2 string) bool
- func (cn *ContextualNormalizer) NormalizeFunctionName(funcName string) (schema, name string)
- func (cn *ContextualNormalizer) NormalizeIdentifier(identifier string) string
- func (cn *ContextualNormalizer) NormalizeSchemaName(schemaName string) string
- func (cn *ContextualNormalizer) NormalizeTableName(tableName string) (schema, table string)
- func (cn *ContextualNormalizer) ParseQualifiedName(qualifiedName string) []string
- type ErrorCollector
- func (ec *ErrorCollector) AddDependencyError(message string, ctx *ParseContext)
- func (ec *ErrorCollector) AddError(err *ParseError)
- func (ec *ErrorCollector) AddNamingWarning(message, suggestion string, ctx *ParseContext)
- func (ec *ErrorCollector) AddPerformanceWarning(message, suggestion string, ctx *ParseContext)
- func (ec *ErrorCollector) AddSemanticError(message, suggestion string, ctx *ParseContext)
- func (ec *ErrorCollector) AddSyntaxError(message string, ctx *ParseContext, innerErr error)
- func (ec *ErrorCollector) GetAllIssues() []*ParseError
- func (ec *ErrorCollector) GetErrors() []*ParseError
- func (ec *ErrorCollector) GetWarnings() []*ParseError
- type ErrorFormatter
- type ErrorHandler
- func (eh *ErrorHandler) CreateContext(filename string, line int, stmt *types.Statement) *ParseContext
- func (eh *ErrorHandler) GetCollector() *ErrorCollector
- func (eh *ErrorHandler) GetReporter() *ErrorReporter
- func (eh *ErrorHandler) HandleParseError(err error, ctx *ParseContext) *ParseError
- func (eh *ErrorHandler) HandleValidationError(message string, ctx *ParseContext) *ParseError
- func (eh *ErrorHandler) LogSummary()
- func (eh *ErrorHandler) Recovery(filename string, line int)
- func (eh *ErrorHandler) ShouldContinue() bool
- type ErrorReporter
- type ErrorSummary
- type KeywordContext
- type KeywordType
- type NormalizationContext
- type ParseContext
- type ParseError
- type StatementAnalyzer
- type StatementProcessingState
- type StmtDecl
- type VersionedKeywordManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractStaticDDLFromDoBlock ¶
ExtractStaticDDLFromDoBlock returns statically-declared DDL statements from a PostgreSQL DO block. Dynamic EXECUTE expressions are intentionally not returned because their final SQL cannot be proven without running the block.
ParseMigration preserves the DO block itself; consolidation rules use this helper when a safety level explicitly permits unwrapping static DDL.
func FormatLockLevel ¶
FormatLockLevel returns a human-readable description of a lock level
func IsValidPostgreSQLIdentifier ¶
IsValidPostgreSQLIdentifier checks if an identifier is valid in PostgreSQL
func ParseMigration ¶
ParseMigration parses a migration file with enhanced PostgreSQL-specific processing
func ParseMigrationWithContext ¶
func ParseMigrationWithContext(ctx context.Context, content string, filename string) (*types.Migration, error)
ParseMigrationWithContext parses a migration file with context and enhanced error handling
func SuggestIdentifierName ¶
SuggestIdentifierName suggests a valid identifier name based on input
Types ¶
type ContextualKeywordChecker ¶
type ContextualKeywordChecker struct {
// contains filtered or unexported fields
}
ContextualKeywordChecker provides context-aware keyword checking
func NewContextualKeywordChecker ¶
func NewContextualKeywordChecker(context KeywordContext, version int) *ContextualKeywordChecker
NewContextualKeywordChecker creates a context-aware keyword checker
func (*ContextualKeywordChecker) IsKeywordInContext ¶
func (ckc *ContextualKeywordChecker) IsKeywordInContext(word string) bool
IsKeywordInContext checks if a word is a keyword in the given context
type ContextualNormalizer ¶
type ContextualNormalizer struct {
// contains filtered or unexported fields
}
ContextualNormalizer handles PostgreSQL identifier normalization with context awareness
func NewContextualNormalizer ¶
func NewContextualNormalizer(ctx *NormalizationContext) *ContextualNormalizer
NewContextualNormalizer creates a normalizer with the given context
func (*ContextualNormalizer) BatchNormalize ¶
func (cn *ContextualNormalizer) BatchNormalize(identifiers []string) ([]string, []error)
BatchNormalize normalizes multiple identifiers with error collection
func (*ContextualNormalizer) CompareIdentifiers ¶
func (cn *ContextualNormalizer) CompareIdentifiers(id1, id2 string) bool
CompareIdentifiers performs case-insensitive comparison according to PostgreSQL rules
func (*ContextualNormalizer) NormalizeFunctionName ¶
func (cn *ContextualNormalizer) NormalizeFunctionName(funcName string) (schema, name string)
NormalizeFunctionName normalizes a function name with overloading support
func (*ContextualNormalizer) NormalizeIdentifier ¶
func (cn *ContextualNormalizer) NormalizeIdentifier(identifier string) string
NormalizeIdentifier normalizes a PostgreSQL identifier according to context
func (*ContextualNormalizer) NormalizeSchemaName ¶
func (cn *ContextualNormalizer) NormalizeSchemaName(schemaName string) string
NormalizeSchemaName normalizes a schema name with proper defaulting
func (*ContextualNormalizer) NormalizeTableName ¶
func (cn *ContextualNormalizer) NormalizeTableName(tableName string) (schema, table string)
NormalizeTableName normalizes a table name, handling schema prefixes
func (*ContextualNormalizer) ParseQualifiedName ¶
func (cn *ContextualNormalizer) ParseQualifiedName(qualifiedName string) []string
ParseQualifiedName parses a qualified name handling quotes properly
type ErrorCollector ¶
type ErrorCollector struct {
*errors.ErrorCollector
}
ErrorCollector now wraps errors.ErrorCollector with ParseError compatibility
func NewErrorCollector ¶
func NewErrorCollector(ctx context.Context) *ErrorCollector
NewErrorCollector creates a new error collector
func (*ErrorCollector) AddDependencyError ¶
func (ec *ErrorCollector) AddDependencyError(message string, ctx *ParseContext)
AddDependencyError adds a dependency error
func (*ErrorCollector) AddError ¶
func (ec *ErrorCollector) AddError(err *ParseError)
AddError adds an error to the collector
func (*ErrorCollector) AddNamingWarning ¶
func (ec *ErrorCollector) AddNamingWarning(message, suggestion string, ctx *ParseContext)
AddNamingWarning adds a naming convention warning
func (*ErrorCollector) AddPerformanceWarning ¶
func (ec *ErrorCollector) AddPerformanceWarning(message, suggestion string, ctx *ParseContext)
AddPerformanceWarning adds a performance warning
func (*ErrorCollector) AddSemanticError ¶
func (ec *ErrorCollector) AddSemanticError(message, suggestion string, ctx *ParseContext)
AddSemanticError adds a semantic error
func (*ErrorCollector) AddSyntaxError ¶
func (ec *ErrorCollector) AddSyntaxError(message string, ctx *ParseContext, innerErr error)
AddSyntaxError adds a syntax error
func (*ErrorCollector) GetAllIssues ¶
func (ec *ErrorCollector) GetAllIssues() []*ParseError
GetAllIssues returns both errors and warnings as ParseErrors
func (*ErrorCollector) GetErrors ¶
func (ec *ErrorCollector) GetErrors() []*ParseError
GetErrors returns all errors as ParseErrors
func (*ErrorCollector) GetWarnings ¶
func (ec *ErrorCollector) GetWarnings() []*ParseError
GetWarnings returns all warnings as ParseErrors
type ErrorFormatter ¶
type ErrorFormatter struct {
*errors.ErrorFormatter
}
ErrorFormatter wraps errors.ErrorFormatter
func NewErrorFormatter ¶
func NewErrorFormatter() *ErrorFormatter
NewErrorFormatter creates a new error formatter
func (*ErrorFormatter) FormatError ¶
func (ef *ErrorFormatter) FormatError(err *ParseError) string
FormatError formats a single error
func (*ErrorFormatter) FormatErrorList ¶
func (ef *ErrorFormatter) FormatErrorList(errorList []*ParseError) string
FormatErrorList formats a list of errors
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler provides centralized error handling
func NewErrorHandler ¶
func NewErrorHandler(ctx context.Context) *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) CreateContext ¶
func (eh *ErrorHandler) CreateContext(filename string, line int, stmt *types.Statement) *ParseContext
CreateContext creates a parse context from available information
func (*ErrorHandler) GetCollector ¶
func (eh *ErrorHandler) GetCollector() *ErrorCollector
GetCollector returns the error collector
func (*ErrorHandler) GetReporter ¶
func (eh *ErrorHandler) GetReporter() *ErrorReporter
GetReporter returns the error reporter
func (*ErrorHandler) HandleParseError ¶
func (eh *ErrorHandler) HandleParseError(err error, ctx *ParseContext) *ParseError
HandleParseError handles a parse error with appropriate logging
func (*ErrorHandler) HandleValidationError ¶
func (eh *ErrorHandler) HandleValidationError(message string, ctx *ParseContext) *ParseError
HandleValidationError handles validation errors
func (*ErrorHandler) LogSummary ¶
func (eh *ErrorHandler) LogSummary()
LogSummary logs a summary of all collected errors and warnings
func (*ErrorHandler) Recovery ¶
func (eh *ErrorHandler) Recovery(filename string, line int)
Recovery handles panic recovery during parsing
func (*ErrorHandler) ShouldContinue ¶
func (eh *ErrorHandler) ShouldContinue() bool
ShouldContinue determines if processing should continue after an error
type ErrorReporter ¶
type ErrorReporter struct {
// contains filtered or unexported fields
}
ErrorReporter handles error reporting and formatting
func NewErrorReporter ¶
func NewErrorReporter(collector *ErrorCollector) *ErrorReporter
NewErrorReporter creates a new error reporter
type ErrorSummary ¶
type ErrorSummary = errors.ErrorSummary
ErrorSummary is now an alias to errors.ErrorSummary
type KeywordContext ¶
type KeywordContext int
KeywordContext represents the context in which a keyword appears
const ( KeywordContextGeneral KeywordContext = iota KeywordContextDDL KeywordContextDML KeywordContextFunction KeywordContextConstraint )
type KeywordType ¶
type KeywordType int
KeywordType represents different types of PostgreSQL keywords
const ( KeywordTypeReserved KeywordType = iota KeywordTypeNonReserved KeywordTypeContextual KeywordTypeUnreserved )
type NormalizationContext ¶
type NormalizationContext struct {
DefaultSchema string `json:"default_schema"`
CaseSensitive bool `json:"case_sensitive"`
PreserveQuotes bool `json:"preserve_quotes"`
MaxIdentifierLength int `json:"max_identifier_length"`
PostgreSQLVersion int `json:"postgresql_version"`
}
NormalizationContext provides context for PostgreSQL identifier normalization
func DefaultNormalizationContext ¶
func DefaultNormalizationContext() *NormalizationContext
DefaultNormalizationContext returns PostgreSQL-compliant defaults
type ParseContext ¶
type ParseContext = errors.ErrorContext
ParseContext scopes errors.ErrorContext to parser operations.
type ParseError ¶
type ParseError struct {
*errors.StructuredError
Statement *types.Statement
}
ParseError represents a structured parsing error with context
func NewNormalizationError ¶
func NewNormalizationError(message string, index int) *ParseError
NewNormalizationError creates a new normalization error
func NewParseError ¶
NewParseError creates a new ParseError wrapping StructuredError
type StatementAnalyzer ¶
type StatementAnalyzer struct {
// contains filtered or unexported fields
}
StatementAnalyzer analyzes SQL statements to determine metadata like lock levels, transaction requirements, and execution characteristics.
func NewStatementAnalyzer ¶
func NewStatementAnalyzer(pgVersion string) *StatementAnalyzer
NewStatementAnalyzer creates a new statement analyzer
func (*StatementAnalyzer) AnalyzePragmas ¶
func (sa *StatementAnalyzer) AnalyzePragmas(stmt *types.Statement)
AnalyzePragmas checks for manual override pragmas in comments
func (*StatementAnalyzer) AnalyzeStatement ¶
func (sa *StatementAnalyzer) AnalyzeStatement(stmt *types.Statement)
AnalyzeStatement analyzes a statement and populates its metadata
type StatementProcessingState ¶
type StatementProcessingState struct {
StatementID string
ProcessedBy []string
FinalState *types.Statement
ConflictFlags []string
DependencySource string // Which function detected the dependencies
}
Processing state to prevent duplicate analysis
type StmtDecl ¶
StmtDecl binds an AST statement node to its source byte range.
Adapted from potential-tools/pgvet/rules/filter.go.
type VersionedKeywordManager ¶
type VersionedKeywordManager struct {
// contains filtered or unexported fields
}
VersionedKeywordManager manages PostgreSQL keywords by version
func NewVersionedKeywordManager ¶
func NewVersionedKeywordManager(version int) *VersionedKeywordManager
NewVersionedKeywordManager creates a keyword manager for a specific PostgreSQL version
func (*VersionedKeywordManager) GetKeywordType ¶
func (vkm *VersionedKeywordManager) GetKeywordType(word string) (KeywordType, bool)
GetKeywordType returns the type of a keyword
func (*VersionedKeywordManager) IsKeyword ¶
func (vkm *VersionedKeywordManager) IsKeyword(word string) bool
IsKeyword checks if a word is a PostgreSQL keyword
func (*VersionedKeywordManager) IsReservedKeyword ¶
func (vkm *VersionedKeywordManager) IsReservedKeyword(word string) bool
IsReservedKeyword checks if a word is a reserved keyword