Documentation
¶
Index ¶
Constants ¶
const ( // NullSentinel stands for SQL NULL. NullSentinel = "NULL" // EmptySentinel stands for a zero-length value — an empty string, or a // zero-length blob. Kind says which. EmptySentinel = `""` )
Display sentinels: the strings Rows carries in place of values that would otherwise render as an empty cell. Producers write them (see dbutil.ScanRowsLimit) and consumers that need the original value read them back together with the cell's Kind (see internal/db/bring).
Variables ¶
This section is empty.
Functions ¶
func DetectType ¶ added in v0.6.0
DetectType returns the database type string for a given DSN.
func DisplayName ¶ added in v0.6.0
DisplayName returns a short display name for a DSN.
func InitialQuery ¶ added in v0.6.0
InitialQuery returns an appropriate initial query for the database type.
func MaskDSN ¶ added in v0.6.0
MaskDSN returns a display-safe version of the DSN with passwords masked.
func Placeholder ¶ added in v0.6.0
Placeholder returns an appropriate placeholder query for the database type.
func URLParseError ¶ added in v0.12.0
URLParseError reports a url.Parse failure for a DSN without leaking it.
Neither half of a url.Parse failure is safe to print. url.Error embeds the raw URL, and its cause embeds a fragment of it — url.EscapeError holds the offending "%xx" sequence, which is the whole password in a DSN like postgres://alice:%ss@host/db. These errors reach stderr and the TUI, so this reports the DSN masked, reduces the cause to the kind of failure, and drops the original error rather than wrapping it, so it cannot travel to a caller that prints it.
It exists so that rule lives in one signature rather than in a comment beside every adapter's url.Parse call: a caller cannot reach for %w without noticing it is stepping around this.
label names the DSN's flavour for the message, e.g. "MySQL" or "PostgreSQL".
Types ¶
type Kind ¶ added in v0.11.0
type Kind uint8
Kind records what a cell's display string in QueryResult.Rows stands for.
Rows is stringified at scan time (see dbutil.StringifyValue), which is the only point where the driver's typed value still exists. Kind captures just enough of that value — its storage class, plus which strings are display sentinels rather than real text — for a consumer to reconstruct the SQL value behind a display string. It is deliberately not a type system: there is no notion of width, signedness, timestamps or booleans, because nothing downstream needs them.
const ( // KindText means the display string is the value verbatim. It is the zero // value, so a QueryResult carrying no Kinds behaves as all-text. KindText Kind = iota // KindNull means SQL NULL. The display string is the "NULL" sentinel. KindNull // KindEmpty means an empty string. The display string is the `""` sentinel. KindEmpty // KindInt means an integer. The display string parses with strconv.ParseInt. KindInt // KindFloat means a floating-point number. The display string parses with // strconv.ParseFloat and round-trips exactly. KindFloat // KindBlob means binary data — either a value that was not valid UTF-8, or // any value from a column the driver declares as binary. The display string // is its lowercase hex encoding and decodes with hex.DecodeString, except // for a zero-length blob, which carries EmptySentinel like any other // zero-length value. KindBlob )
type QueryResult ¶
type QueryResult struct {
Columns []string
ColumnTypes []string // e.g. "INTEGER", "TEXT", "VARCHAR". nil if unavailable.
Rows [][]string
// Kinds is parallel to Rows: Kinds[r][c] describes Rows[r][c]. It is nil
// when the producer did not record kinds, in which case every cell must be
// treated as KindText.
//
// INVARIANT: any transformation that reorders, filters or replaces Rows
// must apply the same transformation to Kinds or clear Kinds entirely.
// Display-only sorting (see ui.sortedRows) does not violate this because it
// writes to the model's displayRows, never back into lastResult.Rows.
Kinds [][]Kind
Message string
Truncated bool // true when rows were capped at the scan limit
}
func (QueryResult) HasKinds ¶ added in v0.11.0
func (r QueryResult) HasKinds() bool
HasKinds reports whether this result carries kind information. Consumers that need to fall back to string-sentinel heuristics should branch on this once rather than per cell.
func (QueryResult) KindAt ¶ added in v0.11.0
func (r QueryResult) KindAt(row, col int) Kind
KindAt returns the kind of the cell at (row, col), or KindText when this result carries no kind information for it.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bring materializes query results from any DBAdapter into a local in-memory SQLite database so they can be JOINed together, per the asql "Bring Data" philosophy: bring data locally rather than integrating heterogeneous databases directly.
|
Package bring materializes query results from any DBAdapter into a local in-memory SQLite database so they can be JOINed together, per the asql "Bring Data" philosophy: bring data locally rather than integrating heterogeneous databases directly. |
|
Package readonly refuses statements that would write, before asql sends them to a database.
|
Package readonly refuses statements that would write, before asql sends them to a database. |