Documentation
¶
Overview ¶
Package output handles formatting and writing query results and errors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteError ¶
WriteError writes an error to stderr as JSON.
Types ¶
type CSVWriter ¶ added in v1.1.0
type CSVWriter struct {
// contains filtered or unexported fields
}
CSVWriter streams rows as CSV. Column order is fixed at construction.
func NewCSVWriter ¶ added in v1.1.0
NewCSVWriter creates a new CSV writer with the given column order.
func (*CSVWriter) WritePagination ¶ added in v1.1.0
func (c *CSVWriter) WritePagination(_ *Pagination) error
WritePagination is a no-op for CSV — no metadata support.
type CompactWriter ¶ added in v1.2.0
type CompactWriter struct {
// contains filtered or unexported fields
}
CompactWriter writes query results as typed NDJSON messages:
{"type":"columns","values":["id","name"]}
{"type":"row","values":[1,"Alice"]}
{"type":"row","values":[2,"Bob"]}
{"type":"pagination","values":{"hasMore":true,"rowCount":2}}
Each line is self-describing and independently parseable. Saves tokens by not repeating column names in every row.
func NewCompactWriter ¶ added in v1.2.0
func NewCompactWriter(w io.Writer, columns []string) *CompactWriter
NewCompactWriter creates a compact result writer.
func (*CompactWriter) Flush ¶ added in v1.2.0
func (c *CompactWriter) Flush() error
func (*CompactWriter) WritePagination ¶ added in v1.2.0
func (c *CompactWriter) WritePagination(p *Pagination) error
type Format ¶
type Format string
Format identifies an output format.
func ParseFormat ¶
ParseFormat parses a format string, returning an error for unknown formats.
func ResolveFormat ¶ added in v1.1.0
ResolveFormat resolves the output format from flag > config > default.
type JSONWriter ¶ added in v1.1.0
type JSONWriter struct {
// contains filtered or unexported fields
}
JSONWriter buffers all rows and writes a single JSON envelope on Flush.
func NewJSONWriter ¶ added in v1.1.0
func NewJSONWriter(w io.Writer, columns []string) *JSONWriter
NewJSONWriter creates a new JSON envelope writer. If columns is non-nil, it defines the column order; otherwise columns are extracted from the first row.
func (*JSONWriter) Flush ¶ added in v1.1.0
func (j *JSONWriter) Flush() error
func (*JSONWriter) WritePagination ¶ added in v1.1.0
func (j *JSONWriter) WritePagination(p *Pagination) error
type NDJSONWriter ¶
type NDJSONWriter struct {
// contains filtered or unexported fields
}
NDJSONWriter writes query results as NDJSON (one JSON object per line).
func NewNDJSONWriter ¶
func NewNDJSONWriter(w io.Writer) *NDJSONWriter
NewNDJSONWriter creates a new NDJSON result writer.
func (*NDJSONWriter) Flush ¶
func (n *NDJSONWriter) Flush() error
func (*NDJSONWriter) WritePagination ¶
func (n *NDJSONWriter) WritePagination(p *Pagination) error
type Pagination ¶
Pagination holds pagination metadata for result sets.
type ResultWriter ¶
type ResultWriter interface {
WriteRow(row map[string]any) error
WritePagination(p *Pagination) error
Flush() error
}
ResultWriter writes query results in a streaming fashion.
type YAMLWriter ¶ added in v1.1.0
type YAMLWriter struct {
// contains filtered or unexported fields
}
YAMLWriter buffers all rows and writes YAML on Flush.
func NewYAMLWriter ¶ added in v1.1.0
func NewYAMLWriter(w io.Writer, columns []string) *YAMLWriter
NewYAMLWriter creates a new YAML writer. If columns is non-nil, it defines the column order; otherwise columns are extracted from the first row.
func (*YAMLWriter) Flush ¶ added in v1.1.0
func (y *YAMLWriter) Flush() error
func (*YAMLWriter) WritePagination ¶ added in v1.1.0
func (y *YAMLWriter) WritePagination(p *Pagination) error