Documentation
¶
Overview ¶
Package state persists per-profile selection state for rdq.
The state file lives at ~/.rdq/state.json (overridable via the RDQ_STATE_FILE env var for tests). Each AWS profile gets its own entry so that switching profiles does not leak cluster/secret/database history between accounts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProfileState ¶
type ProfileState struct {
Cluster string `json:"cluster,omitempty"`
Secret string `json:"secret,omitempty"`
Database string `json:"database,omitempty"`
BedrockModel string `json:"bedrock_model,omitempty"`
BedrockLanguage string `json:"bedrock_language,omitempty"`
DatabaseHistory []string `json:"database_history,omitempty"`
// ClusterSecrets remembers which secret ARN the user picked for each
// cluster ARN within this profile. The lookup is consulted before any
// AWS-side suggestion logic so manually managed secrets (no
// MasterUserSecret, no aws:rds:primaryDBClusterArn tag) still get a
// one-step switch after the first manual selection.
ClusterSecrets map[string]string `json:"cluster_secrets,omitempty"`
// IsProduction marks this profile as a production environment so the
// TUI can paint a distinctive warning theme (red borders, PRODUCTION
// banner) whenever it is active. Tri-state: nil means "the user has
// not answered yet" — the TUI prompts on first activation; a non-nil
// value indicates the user made a deliberate choice and is not asked
// again until they explicitly reopen the toggle.
IsProduction *bool `json:"is_production,omitempty"`
// IsReadOnly, when true, forces the execute path to reject any SQL
// whose leading keyword is not a safe read operation (SELECT / WITH /
// SHOW / EXPLAIN / DESCRIBE / DESC / TABLE / VALUES). nil defaults
// to "enabled" at runtime so a fresh install is safe out of the box;
// users who actively want to run writes must flip it off in Settings.
IsReadOnly *bool `json:"is_read_only,omitempty"`
// AutoRunReadOnly, when true, automatically executes AI-generated SQL
// the moment it comes back from Bedrock, provided runner.IsReadOnly
// classifies it as a safe read. nil / false leaves the existing flow
// (paste into editor, wait for Run) untouched. Manually authored SQL
// is unaffected — auto-run only short-circuits the AI pipeline.
AutoRunReadOnly *bool `json:"auto_run_read_only,omitempty"`
}
type State ¶
type State struct {
Profiles map[string]ProfileState `json:"profiles"`
// contains filtered or unexported fields
}
func Load ¶
Load reads the state file. A missing file yields an empty State; a malformed file yields an error so the caller can decide whether to fall back.
func (*State) Get ¶
func (s *State) Get(profile string) ProfileState
Get returns the state for a profile, or a zero ProfileState if absent. An empty profile name maps to a synthetic "_default_" key.
func (*State) Set ¶
func (s *State) Set(profile string, ps ProfileState)
Set replaces the entry for a profile. The DatabaseHistory is normalized so that the most recently used database moves to the front, duplicates are removed, and the list is capped to historyLimit entries.