Help us shape the future of Go! Take the 2026 Go Developer Survey

explain

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectDriver

func DetectDriver(dsn string) (string, error)

DetectDriver infers the database driver name from a DSN string.

  • "postgres://" or "postgresql://" prefix → "pgx"
  • Contains "@" (MySQL-style user:pass@tcp(…)/db) → "mysql"
  • Contains "=" but not "@" (PostgreSQL key=value style) → "pgx"
  • Otherwise → error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps a database connection for running EXPLAIN queries.

func NewClient

func NewClient(db *sql.DB) *Client

NewClient creates a new Client from an existing *sql.DB.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying database connection.

func (*Client) Run

func (c *Client) Run(ctx context.Context, mode Mode, query string, args []string) (*Result, error)

Run executes EXPLAIN or EXPLAIN ANALYZE for the given query with optional args.

type Mode

type Mode int

Mode selects between EXPLAIN and EXPLAIN ANALYZE.

const (
	Explain Mode = iota // EXPLAIN (plan only)
	Analyze             // EXPLAIN ANALYZE (plan + actual execution)
)

func (Mode) String

func (m Mode) String() string

type Result

type Result struct {
	Plan     string
	Duration time.Duration
}

Result holds the output of an EXPLAIN query.

Jump to

Keyboard shortcuts

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