Documentation
¶
Overview ¶
Package services provides utilities for the advisor tool that can be imported by external programs.
Index ¶
- func CalculateAffectedRowsForStatements(statement string, engineType advisor.Engine, dbParams *DBConnectionParams) map[int]*AffectedRowsInfo
- func FetchDatabaseMetadata(engineType advisor.Engine, dbParams *DBConnectionParams) (*advisor.DatabaseSchemaMetadata, error)
- func GenerateSampleConfig(engineType advisor.Engine) string
- func GetDbTypeString(engineType advisor.Engine) string
- func GetDefaultRules(engineType advisor.Engine, hasMetadata bool) []*advisor.SQLReviewRule
- func ListAvailableRules()
- func LoadRules(configFile string, engineType advisor.Engine, hasMetadata bool) ([]*advisor.SQLReviewRule, error)
- func OutputResults(resp *advisor.ReviewResponse, statement string, engineType advisor.Engine, ...) error
- func SplitSQL(statement string) []string
- type AffectedRowsInfo
- type DBConnectionParams
- type ReviewConfig
- type ReviewResult
- type ReviewRuleEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateAffectedRowsForStatements ¶
func CalculateAffectedRowsForStatements(statement string, engineType advisor.Engine, dbParams *DBConnectionParams) map[int]*AffectedRowsInfo
CalculateAffectedRowsForStatements calculates affected rows for all SQL statements. Returns a map of SQL index to AffectedRowsInfo (count and error).
func FetchDatabaseMetadata ¶
func FetchDatabaseMetadata(engineType advisor.Engine, dbParams *DBConnectionParams) (*advisor.DatabaseSchemaMetadata, error)
FetchDatabaseMetadata fetches database schema metadata from the connected database.
func GenerateSampleConfig ¶
GenerateSampleConfig generates a sample configuration file for the specified engine.
func GetDbTypeString ¶
GetDbTypeString converts Engine type to database type string.
func GetDefaultRules ¶
func GetDefaultRules(engineType advisor.Engine, hasMetadata bool) []*advisor.SQLReviewRule
GetDefaultRules returns default rules based on engine type and whether metadata is available. hasMetadata indicates if database metadata is provided (some rules require it).
func ListAvailableRules ¶
func ListAvailableRules()
ListAvailableRules lists all available SQL review rules.
func LoadRules ¶
func LoadRules(configFile string, engineType advisor.Engine, hasMetadata bool) ([]*advisor.SQLReviewRule, error)
LoadRules loads SQL review rules from a config file or returns default rules.
func OutputResults ¶
func OutputResults(resp *advisor.ReviewResponse, statement string, engineType advisor.Engine, format string, dbParams *DBConnectionParams) error
OutputResults outputs the review results in the specified format.
Types ¶
type AffectedRowsInfo ¶ added in v1.0.8
AffectedRowsInfo holds the count and error information for affected rows calculation.
type DBConnectionParams ¶
type DBConnectionParams struct {
Host string
Port int
User string
Password string
DbName string
Charset string
ServiceName string
Sid string
SSLMode string
Timeout int
Schema string
}
DBConnectionParams holds database connection parameters.
type ReviewConfig ¶
type ReviewConfig struct {
Name string `json:"name" yaml:"name"`
Rules []*ReviewRuleEntry `json:"rules" yaml:"rules"`
}
ReviewConfig represents a review configuration file.
type ReviewResult ¶
type ReviewResult struct {
OrderID int `json:"order_id"`
Stage string `json:"stage"`
ErrorLevel string `json:"error_level"`
StageStatus string `json:"stage_status"`
ErrorMessage string `json:"error_message"`
SQL string `json:"sql"`
AffectedRows int `json:"affected_rows"`
Sequence string `json:"sequence"`
BackupDBName string `json:"backup_dbname"`
ExecuteTime string `json:"execute_time"`
SQLSha1 string `json:"sqlsha1"`
BackupTime string `json:"backup_time"`
}
ReviewResult represents the review result in Inception-compatible format.
func ConvertToReviewResults ¶
func ConvertToReviewResults(resp *advisor.ReviewResponse, statement string, engineType advisor.Engine, affectedRowsMap map[int]*AffectedRowsInfo) []ReviewResult
ConvertToReviewResults converts advisor response to Inception-compatible format.
type ReviewRuleEntry ¶
type ReviewRuleEntry struct {
Type string `json:"type" yaml:"type"`
Level string `json:"level" yaml:"level"`
Payload string `json:"payload,omitempty" yaml:"payload,omitempty"`
Engine string `json:"engine,omitempty" yaml:"engine,omitempty"`
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
}
ReviewRuleEntry represents a single rule entry in the config file.