- cmd/root.go: Cobra root with all 11 subcommands, viper config loading - cmd/stubs.go: 8 stub commands for future phases (verify, import, recon, keys, serve, dorks, hook, schedule) - cmd/scan.go: scan command wiring engine + storage + output with per-installation salt - cmd/providers.go: providers list/info/stats subcommands - cmd/config.go: config init/set/get subcommands - pkg/config/config.go: Config struct with Load() and defaults - pkg/output/table.go: lipgloss terminal table for PrintFindings - pkg/storage/settings.go: GetSetting/SetSetting for settings table CRUD
34 lines
968 B
Go
34 lines
968 B
Go
package storage
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
// GetSetting retrieves a value from the settings table.
|
|
// Returns (value, true, nil) if found, ("", false, nil) if not found, ("", false, err) on error.
|
|
func (db *DB) GetSetting(key string) (string, bool, error) {
|
|
var value string
|
|
err := db.sql.QueryRow("SELECT value FROM settings WHERE key = ?", key).Scan(&value)
|
|
if err == sql.ErrNoRows {
|
|
return "", false, nil
|
|
}
|
|
if err != nil {
|
|
return "", false, fmt.Errorf("getting setting %q: %w", key, err)
|
|
}
|
|
return value, true, nil
|
|
}
|
|
|
|
// SetSetting inserts or updates a key-value pair in the settings table.
|
|
func (db *DB) SetSetting(key, value string) error {
|
|
_, err := db.sql.Exec(
|
|
`INSERT INTO settings (key, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)
|
|
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP`,
|
|
key, value,
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("setting %q: %w", key, err)
|
|
}
|
|
return nil
|
|
}
|