Documentation
¶
Overview ¶
Package csv is the CSV backend for xql. It loads delimited text files into the shared cell.Table substrate (with inferred per-column types) and writes modified tables back. The executor lives alongside the loader because both share the CSV-specific quirks: BOM handling, delimiter override, sample- based type inference, and round-trip formatting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadCSV ¶
func LoadCSV(path string, opts LoadOptions) (*cell.Table, error)
LoadCSV reads the file at path and returns a fully populated cell.Table. Type inference runs over the first SampleN rows (default 1024); a column gets the most specific type where every sampled non-empty cell parses.
func LoadCSVReader ¶ added in v1.4.0
LoadCSVReader is the io.Reader form of LoadCSV. The label is purely cosmetic -- it populates Table.Path (used in REPL banners and Refresh output) and appears in load-time error messages. Non-file backends pass something user-recognizable like "xinglet://<uuid>".
Types ¶
type Executor ¶
type Executor struct {
Table *cell.Table
Mode string
Headers bool
ConfirmDestructive bool
Confirm func() bool
OutputPath string
Out io.Writer
}
Executor binds a parsed statement to the loaded CSV cell.Table and runs it. One Executor per session.
Confirm is the interactive "Apply? y/N" callback used by the REPL. When non-nil, write executors will call it after the dry-run preview to decide whether to commit (unless commit is already true via the trailing '!'). --exec mode leaves Confirm nil so writes either dry-run or commit explicitly based on --commit.
OutputPath, when non-empty, redirects committed writes to a different file than the bound CSV. Empty means "write back to cell.Table.Path".
func (*Executor) Describe ¶
Describe renders the bound table's columns and inferred types to w using the executor's current format. Wired into the REPL's "describe" meta-cmd. The arg is accepted for signature parity with the SP backend's hidden- column toggle; CSV columns have no hidden flag, so any non-empty arg is rejected.
func (*Executor) Execute ¶
Execute dispatches to the per-statement handler. The commit flag distinguishes dry-run (commit=false: preview only) from a real write (commit=true: preview + apply). It is ignored for SELECT.
func (*Executor) Refresh ¶
Refresh re-reads the bound CSV from disk. Dialect (delimiter, header presence) and the previously-inferred types are preserved as hints so the re-load doesn't accidentally drift the schema mid-session.
func (*Executor) SetConfirm ¶
SetConfirm wires the REPL's y/N callback into the executor's destructive- write confirmation hook. Called once by repl.Run via Session.SetConfirm.
type LoadOptions ¶
type LoadOptions struct {
Delim rune
NoHeader bool
TypeHints map[string]cell.ColumnType
SampleN int
}
LoadOptions controls CSV parsing and type inference. Zero values mean "use defaults": comma delimiter, header row present, type inference enabled.