dbconn

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package dbconn opens read-only, time-limited connections to MySQL and MariaDB servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Address

func Address(cfg *mysql.Config) string

Address renders where the server is, without credentials.

func Describe

func Describe(cfg *mysql.Config) string

Describe renders the connection target without the password, e.g. shop_ro@db.internal:3306/shop.

func ParseDSN

func ParseDSN(dsn, password string) (*mysql.Config, error)

ParseDSN reads a connection string in either of these forms:

mysql://user:pass@host:3306/dbname?tls=true
user:pass@tcp(host:3306)/dbname?tls=true

The URL form also accepts ?socket=/path/to/mysqld.sock. When the DSN has no password, password (usually from PRODMASK_PASSWORD) is used instead.

func WritePrivileges

func WritePrivileges(grants []string, database string) []string

WritePrivileges reads SHOW GRANTS output and returns the privileges that would let the user change the given database.

Types

type Session

type Session struct {
	DB       *sql.DB
	Server   model.ServerInfo
	Database string
	Timeout  time.Duration
	Warnings []string
}

Session is a pool of exactly one connection to the scanned database. Every connection in it is read-only, gives up waiting for metadata locks after a few seconds, and has a server-side statement timeout. Statements run one at a time, and autocommit is on, so no lock or snapshot outlives a statement. When a timeout kills the connection, database/sql opens a new one with the same settings.

func Open

func Open(ctx context.Context, cfg *mysql.Config, timeout time.Duration) (*Session, error)

Open connects, checks the server and the user's privileges, and prepares the read-only session.

func (*Session) Close

func (s *Session) Close() error

Close closes the pool.

func (*Session) Flavor

func (s *Session) Flavor() string

Flavor is "mariadb" or "mysql".

Jump to

Keyboard shortcuts

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