Documentation
¶
Overview ¶
Package db provides database-related utilities including affected rows calculation.
Package db provides database connection utilities for the advisor tool.
Index ¶
- func CalculateAffectedRows(ctx context.Context, conn *sql.DB, statement string, engine advisor.Engine) (int, error)
- func GetDatabaseMetadata(ctx context.Context, db *sql.DB, config *ConnectionConfig) (*storepb.DatabaseSchemaMetadata, error)
- func OpenConnection(ctx context.Context, config *ConnectionConfig) (*sql.DB, error)
- func TestConnection(ctx context.Context, config *ConnectionConfig) error
- type ConnectionConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateAffectedRows ¶
func CalculateAffectedRows(ctx context.Context, conn *sql.DB, statement string, engine advisor.Engine) (int, error)
CalculateAffectedRows 计算 UPDATE/DELETE 语句的影响行数 通过将 UPDATE/DELETE 改写为 SELECT COUNT(1) 查询来估算
func GetDatabaseMetadata ¶
func GetDatabaseMetadata(ctx context.Context, db *sql.DB, config *ConnectionConfig) (*storepb.DatabaseSchemaMetadata, error)
GetDatabaseMetadata retrieves the database schema metadata.
func OpenConnection ¶
OpenConnection opens a database connection based on the configuration.
func TestConnection ¶
func TestConnection(ctx context.Context, config *ConnectionConfig) error
TestConnection tests if the database connection is valid.
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
DbType string // mysql, postgres, mssql, oracle
Host string
Port int
User string
Password string
DbName string
Charset string
ServiceName string // For Oracle
Sid string // For Oracle
SSLMode string // For PostgreSQL
Timeout int // Connection timeout in seconds
Schema string // For PostgreSQL
SetSearchPath bool // For PostgreSQL: whether to set search_path (only for affected rows calculation)
}
ConnectionConfig holds database connection configuration.
Click to show internal directories.
Click to hide internal directories.