csv

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 13 Imported by: 0

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

func LoadCSVReader(label string, src io.Reader, opts LoadOptions) (*cell.Table, error)

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>".

func SaveCSV

func SaveCSV(t *cell.Table, dst string) error

SaveCSV writes the cell.Table back to its bound path (or to dst if non-empty). Cells emit in their canonical string form; NULL becomes an empty field.

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

func (e *Executor) Describe(w io.Writer, arg string) error

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

func (e *Executor) Execute(stmt parse.Stmt, commit bool) error

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

func (e *Executor) Refresh() error

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

func (e *Executor) SetConfirm(fn func() bool)

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.

Jump to

Keyboard shortcuts

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