Documentation
¶
Overview ¶
Package result formats query values for display and export.
Formatting lives apart from the UI so the grid, CSV export and JSON export all agree on what a value looks like — and so the rules can be tested without a terminal.
Index ¶
- Constants
- func Compare(a, b any, order Order) int
- func EscapeTags(s string) string
- func Format(v any) string
- func Truncate(s string, limit int) string
- type Buffer
- func (b *Buffer) Append(rows [][]any) int
- func (b *Buffer) AtCapacity() bool
- func (b *Buffer) Cell(row, col int) string
- func (b *Buffer) ColumnCount() int
- func (b *Buffer) ColumnName(col int) string
- func (b *Buffer) ColumnType(col int) string
- func (b *Buffer) Columns() []string
- func (b *Buffer) Raw(row, col int) any
- func (b *Buffer) Reset()
- func (b *Buffer) Row(row int) []any
- func (b *Buffer) RowCount() int
- func (b *Buffer) SetColumns(columns []string, types []*sql.ColumnType)
- type Order
Constants ¶
const CellLimit = 200
CellLimit caps how many runes a grid cell shows. Long values stay in the buffer intact; only the rendering is shortened.
const NullText = "NULL"
NullText is how a SQL NULL is shown. It has to be visually distinct from an empty string: treating the two alike misleads people into thinking a row failed an IS NULL test for no reason.
const TimeLayout = "2006-01-02 15:04:05"
TimeLayout is the timestamp rendering, chosen to match MySQL's own.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶ added in v0.4.0
Compare orders two values of one column, returning the usual negative, zero or positive.
NULL sorts first, as it does in an ascending ORDER BY. Anything that cannot be read as the column's kind sorts after everything that can and then ties on its text, so a stray value in a numeric column lands somewhere it can be seen rather than somewhere arbitrary.
func EscapeTags ¶
EscapeTags neutralises tview's colour-tag syntax.
tview reads "[" as the start of a tag, so a cell containing "[red]" would recolour the grid instead of showing its own text. tview's documented escape is to write "[" as "[[".
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer holds the rows of one result set.
It is written by the streaming goroutine and read by the UI goroutine, so every accessor takes the lock. Reads outside the current bounds return zero values rather than panicking: tview asks for cells while rendering, and a result that was just cleared would otherwise crash the application.
func (*Buffer) AtCapacity ¶
AtCapacity reports whether the buffer has stopped accepting rows.
func (*Buffer) ColumnCount ¶
ColumnCount is the number of columns in the result.
func (*Buffer) ColumnName ¶
ColumnName returns the name of a column, or "" if it is out of range.
func (*Buffer) ColumnType ¶ added in v0.3.0
ColumnType names the column's database type — BIGINT, VARCHAR — or "" when the driver did not say.
A driver is allowed to report nothing, and several statements produce no type information at all, so the caller has to be able to show less rather than showing a blank where a type was promised.
func (*Buffer) RowCount ¶
RowCount is the number of rows received so far. While a stream is running it grows, which is what lets the grid scroll through partial results.
func (*Buffer) SetColumns ¶
func (b *Buffer) SetColumns(columns []string, types []*sql.ColumnType)
SetColumns replaces the result header and drops any existing rows.
type Order ¶ added in v0.4.0
type Order int
Order is how a column's values are put in sequence.
func OrderFor ¶ added in v0.4.0
OrderFor decides from the column's declared type.
It is the type that decides and never the values, because values reach here as bytes: everything a query returns over the text protocol is a []byte, so "9" and "10" look alike whether the column is a BIGINT or a VARCHAR. Guessing from the bytes would sort a VARCHAR numerically and disagree with the server about its own column.
An unknown type is text. A driver is allowed to report nothing, and an ordering a column cannot justify is worse than a coarse one.