db

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package db provides database-related utilities including affected rows calculation.

Package db provides database connection utilities for the advisor tool.

Index

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

func OpenConnection(ctx context.Context, config *ConnectionConfig) (*sql.DB, error)

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.

Jump to

Keyboard shortcuts

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