Documentation
¶
Overview ¶
Package sqlflags implements the shared CLI flag grammar for the SQL-verb commands (select, insert, update, delete, drop).
Each parser is a pure function. Each flag-registration helper takes a *cobra.Command and adds the flag with the documented metadata. The package is the single source of truth for:
- --where comparison operators (==, ===, !=, !==, >=, <=, >, <)
- --set YAML-inferred assignments
- --unset comma-separated field removal list
- --id collection/key targeting (single-record mode)
- --from collection targeting (set mode)
- --into collection targeting (insert only)
- --all full-collection scope guard
- --min-affected positive-integer count threshold
- --order-by comma-separated, '-' prefix for descending
- --fields '*', '$id', or comma-separated projection
Mode resolution (single-record vs set) is handled by ResolveMode. Applicability checks (which verb accepts which flag) are handled by the Reject* helpers. Authoritative spec: spec/features/shared-cli-flags/README.md
Index ¶
- func MinAffectedFromCmd(cmd *cobra.Command) (int, bool, error)
- func ParseFields(s string) ([]string, error)
- func ParseMinAffected(s string) (int, error)
- func ParseUnset(s string) ([]string, error)
- func RegisterAllFlag(cmd *cobra.Command)
- func RegisterFieldsFlag(cmd *cobra.Command)
- func RegisterFromFlag(cmd *cobra.Command)
- func RegisterIDFlag(cmd *cobra.Command)
- func RegisterIntoFlag(cmd *cobra.Command)
- func RegisterMinAffectedFlag(cmd *cobra.Command)
- func RegisterOrderByFlag(cmd *cobra.Command)
- func RegisterSetFlag(cmd *cobra.Command)
- func RegisterUnsetFlag(cmd *cobra.Command)
- func RegisterWhereFlag(cmd *cobra.Command)
- func RejectSetModeFlags(f SetModeFlags, mode Mode) error
- func RejectSetUnsetSameField(sets []Assignment, unsets []string) error
- type Assignment
- type Condition
- type Mode
- type Operator
- type OrderTerm
- type SetModeFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MinAffectedFromCmd ¶
MinAffectedFromCmd reads --min-affected from cmd, returning the parsed value, a "supplied" boolean, and any error. When the flag is not supplied, returns (0, false, nil). When supplied with N >= 1, returns (N, true, nil). When supplied with N < 1, returns an error.
Verb commands should prefer this helper over GetInt because it distinguishes "not supplied" (no threshold check) from "explicit 0" (which is rejected by the spec).
func ParseFields ¶
ParseFields parses --fields. Returns nil for "*" or empty (meaning "all fields"). Otherwise returns the trimmed comma-separated list, preserving order. Empty entries (stray commas) are rejected for consistency with ParseOrderBy and ParseUnset.
func ParseMinAffected ¶
ParseMinAffected parses --min-affected=N into a positive integer. N must be >= 1; zero and negative values are rejected.
func ParseUnset ¶
ParseUnset parses a comma-separated --unset field list. Each field must be non-empty, contain no '=', and contain no whitespace inside the name.
func RegisterAllFlag ¶
RegisterAllFlag adds --all. Used by update, delete.
func RegisterFieldsFlag ¶
RegisterFieldsFlag adds --fields -f. Used by select.
func RegisterFromFlag ¶
RegisterFromFlag adds --from. Used by select, update, delete.
func RegisterIDFlag ¶
RegisterIDFlag adds --id. Used by select, update, delete.
func RegisterIntoFlag ¶
RegisterIntoFlag adds --into. Used by insert only.
func RegisterMinAffectedFlag ¶
RegisterMinAffectedFlag adds --min-affected. Used by select, update, delete.
func RegisterOrderByFlag ¶
RegisterOrderByFlag adds --order-by. Used by select.
func RegisterSetFlag ¶
RegisterSetFlag adds repeatable --set. Used by update.
func RegisterUnsetFlag ¶
RegisterUnsetFlag adds repeatable --unset. Used by update.
func RegisterWhereFlag ¶
RegisterWhereFlag adds repeatable --where -w. Used by select, update, delete in set mode.
func RejectSetModeFlags ¶
func RejectSetModeFlags(f SetModeFlags, mode Mode) error
RejectSetModeFlags enforces the cross-flag rules that depend on the resolved Mode.
In ModeID (single-record): --where, --all, and --min-affected MUST all be absent.
In ModeFrom (set): exactly one of --where or --all MUST be supplied; neither and both are rejected. --min-affected is unconstrained at this layer (it has its own validation in ParseMinAffected and its own applicability rule against ModeID).
func RejectSetUnsetSameField ¶
func RejectSetUnsetSameField(sets []Assignment, unsets []string) error
RejectSetUnsetSameField enforces that no field name appears in both --set and --unset within the same invocation.
Types ¶
type Assignment ¶
Assignment is one parsed --set expression.
func ParseSet ¶
func ParseSet(s string) (Assignment, error)
ParseSet parses one --set expression: `field=value`. Comparison operators between field and value are rejected.
type Condition ¶
Condition is the parsed form of one --where expression.
func ParseWhere ¶
ParseWhere parses one --where expression. The bare `=` operator is rejected (spec: req:comparison-operators).
type Mode ¶
type Mode int
Mode is the verb operating mode.
func ResolveMode ¶
ResolveMode returns the operating mode for a verb based on its --id and --from flag values. Empty string means "not supplied". Supplying both or neither is rejected.
type OrderTerm ¶
OrderTerm is one parsed --order-by entry.
func ParseOrderBy ¶
ParseOrderBy parses a comma-separated --order-by list. A leading '-' indicates descending order for that field. An empty input returns nil with no error.
type SetModeFlags ¶
SetModeFlags carries the boolean presence of set-mode-only flags for applicability checking. Verb-specific flags (--limit, --fields) remain the verb's concern; this helper covers only the shared shape governed by shared-cli-flags.