sqlcdebug

package
v1.13.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sqlcdebug parses the SQLCDEBUG environment variable and exposes its key=value settings to the rest of the codebase.

The SQLCDEBUG variable is a comma-separated list of name=value pairs:

SQLCDEBUG=dumpast=1,trace=trace.out

Settings are looked up at the call site by declaring a package-level variable:

var dumpAST = sqlcdebug.New("dumpast")

func parse() {
    if dumpAST.Value() == "1" { ... }
}

New panics if name is not registered in Settings below. Adding a new setting therefore requires extending the Settings table so that all known keys are documented in one place.

This package is modeled after Go's internal/godebug. Unlike Go, sqlc is short-lived, so settings are parsed once at process startup; the Update hook exists for tests that need to reparse mid-run.

Index

Constants

This section is empty.

Variables

View Source
var Settings = []Info{
	{Name: "dumpast", Description: "print the AST of every SQL statement"},
	{Name: "dumpcatalog", Description: "print the parsed database schema"},
	{Name: "trace", Description: "write a runtime trace to the named file (1 means trace.out)"},
	{Name: "processplugins", Description: "set to 0 to disable process-based plugins", Default: "1"},
	{Name: "databases", Description: "set to 'managed' to disable database connections via URI"},
	{Name: "dumpvetenv", Description: "print the variables available to a vet rule during evaluation"},
	{Name: "dumpexplain", Description: "print the JSON-formatted output from EXPLAIN during vet evaluation"},
}

Settings is the master table of all known SQLCDEBUG keys. New keys must be added here before they can be looked up via New.

Functions

func Any

func Any() bool

Any reports whether SQLCDEBUG contained any recognized key=value pair. It mirrors the legacy "is debug active?" check.

func Update

func Update(raw string)

Update reparses the given SQLCDEBUG-formatted string and refreshes every registered setting. Intended for tests; production code should rely on the value parsed at startup.

Types

type Info

type Info struct {
	// Name is the SQLCDEBUG key, e.g. "dumpast".
	Name string
	// Description is a short human-readable description.
	Description string
	// Default is the value returned by [Setting.Value] when the key is
	// not present in SQLCDEBUG.
	Default string
}

Info documents a single SQLCDEBUG setting.

type Setting

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

Setting is a single SQLCDEBUG key. Obtain one with New; reading it with Setting.Value returns the value parsed from the SQLCDEBUG environment variable, or the registered default.

func New

func New(name string) *Setting

New returns the Setting for name. The same pointer is returned for repeated calls. New panics if name is not present in Settings.

func (*Setting) Default

func (s *Setting) Default() string

Default returns the value used when the key is absent from SQLCDEBUG.

func (*Setting) IsSet

func (s *Setting) IsSet() bool

IsSet reports whether the key was present in SQLCDEBUG.

func (*Setting) Name

func (s *Setting) Name() string

Name returns the setting's key.

func (*Setting) Value

func (s *Setting) Value() string

Value returns the parsed value of the SQLCDEBUG setting, falling back to the registered default.

Jump to

Keyboard shortcuts

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