output

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package output serializes query results into CLI-friendly formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, format string, result Result) error

Write renders result to w using the requested format. The empty format is treated as "table" so CLI callers get a readable default without extra flags.

Types

type LimitWriter

type LimitWriter struct {
	Writer io.Writer
	Limit  int
	// contains filtered or unexported fields
}

LimitWriter wraps another writer and fails once the configured byte limit is exceeded. A non-positive Limit disables the guard and passes writes through.

func (*LimitWriter) Write

func (w *LimitWriter) Write(p []byte) (int, error)

Write writes p to the underlying writer while accounting for the configured byte budget. If p would exceed the limit, it writes the remaining bytes and returns an error so callers can stop producing output.

type Result

type Result struct {
	Columns   []string        `json:"columns" yaml:"columns"`
	Rows      [][]interface{} `json:"rows" yaml:"rows"`
	RowCount  int             `json:"row_count" yaml:"row_count"`
	ElapsedMS int64           `json:"elapsed_ms" yaml:"elapsed_ms"`
}

Result is the database execution payload shared by output encoders. Columns is empty for statements that do not return rows, while RowCount and ElapsedMS still describe the completed operation.

type StreamWriter

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

StreamWriter renders row results incrementally so callers do not need to keep the full result set in memory before writing output.

func NewStreamWriter

func NewStreamWriter(w io.Writer, format string, columns []string, elapsedMS func() int64) (*StreamWriter, error)

NewStreamWriter starts an incremental result writer for row-returning queries.

func (*StreamWriter) Close

func (sw *StreamWriter) Close() (Result, error)

Close finalizes output and returns the result summary.

func (*StreamWriter) RowCount

func (sw *StreamWriter) RowCount() int

RowCount returns how many rows have been streamed so far.

func (*StreamWriter) WriteRow

func (sw *StreamWriter) WriteRow(row []interface{}) error

WriteRow writes one result row.

Jump to

Keyboard shortcuts

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