config

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles reading and writing the agent-sql configuration file. Config lives at $XDG_CONFIG_HOME/agent-sql/config.json (default ~/.config/agent-sql/).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache forces a re-read on next access.

func ConfigDir

func ConfigDir() string

ConfigDir returns the config directory, creating it if needed.

func GetConnections

func GetConnections() map[string]Connection

GetConnections returns all connections.

func GetDefaultAlias

func GetDefaultAlias() string

GetDefaultAlias returns the default connection alias, or empty string.

func GetSetting

func GetSetting(key string) any

GetSetting reads a dotted config key (e.g. "query.timeout").

func RemoveConnection

func RemoveConnection(alias string) error

RemoveConnection removes a connection by alias.

func ResetSettings

func ResetSettings() error

ResetSettings clears all settings to defaults.

func SetConfigDir

func SetConfigDir(dir string)

SetConfigDir overrides the config directory (for testing).

func SetDefault

func SetDefault(alias string) error

SetDefault sets the default connection alias.

func StoreConnection

func StoreConnection(alias string, conn Connection) error

StoreConnection saves a connection. First connection becomes the default.

func UpdateSetting

func UpdateSetting(key string, value any) error

UpdateSetting writes a dotted config key.

func Write

func Write(cfg *Config) error

Write saves the configuration to disk.

Types

type Config

type Config struct {
	DefaultConnection string                `json:"default_connection,omitempty"`
	Connections       map[string]Connection `json:"connections"`
	Settings          Settings              `json:"settings"`
}

Config is the top-level configuration structure.

func Read

func Read() *Config

Read returns the current configuration.

type Connection

type Connection struct {
	Driver     string            `json:"driver"`
	Host       string            `json:"host,omitempty"`
	Port       int               `json:"port,omitempty"`
	Database   string            `json:"database,omitempty"`
	Path       string            `json:"path,omitempty"`
	URL        string            `json:"url,omitempty"`
	Credential string            `json:"credential,omitempty"`
	Account    string            `json:"account,omitempty"`
	Warehouse  string            `json:"warehouse,omitempty"`
	Role       string            `json:"role,omitempty"`
	Schema     string            `json:"schema,omitempty"`
	Options    map[string]string `json:"options,omitempty"`
}

Connection represents a saved database connection.

func GetConnection

func GetConnection(alias string) *Connection

GetConnection returns a connection by alias, or nil if not found.

func (Connection) AsReceipt added in v1.6.0

func (c Connection) AsReceipt(alias string, isDefault bool) map[string]any

AsReceipt renders the curated public view of this connection for CLI output (used by `connection add`, `connection update`, and `connection list`). Raw storage fields (path, url) are intentionally omitted -- display_url is the canonical view and includes effective host:port + appended options. Empty strings, zero ints, and empty maps are dropped so the emitted JSON has no "host: \"\"" noise.

func (Connection) DisplayURL added in v1.3.0

func (c Connection) DisplayURL() string

DisplayURL builds a human-readable connection URL from config fields. Never includes credentials -- only the connection target. Render-time only: it backfills empty host/port/database from c.URL and applies the per-driver default port so the listing reflects what would actually be used at connect time. Stored Options are appended as `?key=value&...` (alphabetized) for URL-form drivers. Storage is not modified.

func (Connection) EffectiveHost added in v1.6.0

func (c Connection) EffectiveHost() string

EffectiveHost returns the connection's host for display, derived the same way as DisplayURL: stored Host, then parsed from URL. For drivers where "host" doesn't apply (sqlite, duckdb), returns "". For snowflake, returns the account identifier.

func (Connection) EffectivePort added in v1.6.0

func (c Connection) EffectivePort() int

EffectivePort returns the connect-time port for host:port drivers: stored Port, then parsed from URL, then the per-driver default. Returns 0 for drivers without a port (sqlite, duckdb, snowflake).

type ConnectionNotFoundError

type ConnectionNotFoundError struct {
	Alias     string
	Available []string
}

ConnectionNotFoundError is returned when a connection alias doesn't exist.

func (*ConnectionNotFoundError) Error

func (e *ConnectionNotFoundError) Error() string

type DefaultsSettings

type DefaultsSettings struct {
	Limit  *int   `json:"limit,omitempty"`
	Format string `json:"format,omitempty"`
}

DefaultsSettings holds default output settings.

type QuerySettings

type QuerySettings struct {
	Timeout *int `json:"timeout,omitempty"`
	MaxRows *int `json:"maxRows,omitempty"`
}

QuerySettings holds query execution settings.

type Settings

type Settings struct {
	Defaults   *DefaultsSettings   `json:"defaults,omitempty"`
	Query      *QuerySettings      `json:"query,omitempty"`
	Truncation *TruncationSettings `json:"truncation,omitempty"`
}

Settings holds persistent configuration settings.

type TruncationSettings

type TruncationSettings struct {
	MaxLength *int `json:"maxLength,omitempty"`
}

TruncationSettings holds string truncation settings.

Jump to

Keyboard shortcuts

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