output

package
v0.6.10 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcTableWidth

func CalcTableWidth(result *executor.QueryResult) int

CalcTableWidth returns the display width (in runes) that a table-formatted result would require. Returns 0 if the result has no columns.

func CalcTableWidthWithMax added in v0.5.0

func CalcTableWidthWithMax(result *executor.QueryResult, maxWidth int) int

CalcTableWidthWithMax returns the display width after smart column truncation.

func ExportResult

func ExportResult(result *executor.QueryResult, path string, format ExportFormat) (int, error)

ExportResult writes a query result to a file in the specified format. Returns the number of rows exported.

func FormatValuePlain added in v0.2.0

func FormatValuePlain(v interface{}) string

FormatValuePlain returns the plain text representation of a value (no ANSI codes). Exported for use by other packages (e.g., pipe output).

Types

type ExportFormat

type ExportFormat int

ExportFormat represents the file format for exporting query results.

const (
	ExportCSV ExportFormat = iota
	ExportJSON
	ExportMarkdown
)

func InferExportFormat

func InferExportFormat(path string) (ExportFormat, error)

InferExportFormat infers the export format from a file extension.

func ParseExportFormat

func ParseExportFormat(s string) (ExportFormat, error)

ParseExportFormat parses a format string and returns the ExportFormat.

func (ExportFormat) String

func (f ExportFormat) String() string

String returns the string representation of an ExportFormat.

type Format

type Format int

Format represents the output format type.

const (
	FormatTable Format = iota
	FormatVertical
	FormatJSON
	FormatMarkdown
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat parses a format string and returns the Format enum.

func (Format) String

func (f Format) String() string

String returns the string representation of a Format.

type Formatter

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

Formatter formats and writes query results.

func NewFormatter

func NewFormatter(format Format, writer io.Writer) *Formatter

NewFormatter creates a new Formatter with the given format and writer.

func (*Formatter) CurrentFormat

func (f *Formatter) CurrentFormat() Format

CurrentFormat returns the current output format.

func (*Formatter) MaxWidth added in v0.5.0

func (f *Formatter) MaxWidth() int

MaxWidth returns the current max width setting.

func (*Formatter) SetFormat

func (f *Formatter) SetFormat(format Format)

SetFormat changes the output format.

func (*Formatter) SetMaxWidth added in v0.5.0

func (f *Formatter) SetMaxWidth(w int)

SetMaxWidth sets the maximum terminal width for column truncation. A value of 0 means unlimited (no truncation).

func (*Formatter) SetShowHeader added in v0.6.6

func (f *Formatter) SetShowHeader(show bool)

SetShowHeader controls whether the column header row is displayed.

func (*Formatter) SetShowTiming added in v0.2.0

func (f *Formatter) SetShowTiming(show bool)

SetShowTiming controls whether execution time is displayed.

func (*Formatter) ShowHeader added in v0.6.6

func (f *Formatter) ShowHeader() bool

ShowHeader returns whether the column header row is displayed.

func (*Formatter) ShowTiming added in v0.2.0

func (f *Formatter) ShowTiming() bool

ShowTiming returns whether execution time display is enabled.

func (*Formatter) WriteResult

func (f *Formatter) WriteResult(result *executor.QueryResult) error

WriteResult writes a QueryResult to the underlying writer using the current format.

Jump to

Keyboard shortcuts

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