schema

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package schema fetches and caches database table/column metadata from information_schema so the TUI can include schema context in AI prompts.

The cache lives at ~/.rdq/schema/<sha256(cluster:database)[:16]>.json (overridable via RDQ_SCHEMA_DIR). There is no automatic TTL — users can manually delete a cache file to force a re-fetch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveCache

func SaveCache(s *Snapshot) error

SaveCache writes a snapshot to disk atomically (tempfile + rename) so a concurrent reader never sees a half-written file.

Types

type Column

type Column struct {
	Schema string `json:"schema"`
	Table  string `json:"table"`
	Name   string `json:"name"`
	Type   string `json:"type"`
}

Column is one row from information_schema.columns flattened into a struct.

type Snapshot

type Snapshot struct {
	Cluster   string    `json:"cluster"`
	Database  string    `json:"database"`
	FetchedAt time.Time `json:"fetched_at"`
	Columns   []Column  `json:"columns"`
}

Snapshot captures the full set of columns for one (cluster, database) pair at a point in time.

func Fetch

func Fetch(ctx context.Context, client *rdsdata.Client, cluster, secret, database string) (*Snapshot, error)

Fetch executes the introspection query against the given cluster and database and returns a Snapshot. Caller is expected to wrap network errors with retry semantics if needed; this function returns them unwrapped so the TUI can decide whether to fall back to an empty schema.

The owner-filtered query is attempted first so PostgreSQL users never see `information_schema` / `pg_catalog` noise in the sidebar. On the first error (typically Aurora MySQL, which lacks schema_owner) it retries with the simple query; only if the retry also fails does the error propagate.

func LoadCache

func LoadCache(cluster, database string) (*Snapshot, error)

LoadCache reads a previously-saved Snapshot from disk. A missing file is not an error; callers can interpret nil as "no cache yet".

func (*Snapshot) ToPrompt

func (s *Snapshot) ToPrompt() string

ToPrompt formats the snapshot as a CREATE TABLE-style listing suitable for embedding in an LLM system prompt. The output groups columns by table and lists "name type" for each. Schemas other than "public" or the database itself are prefixed.

Jump to

Keyboard shortcuts

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