metadata

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package metadata caches the server objects that completion needs: databases, tables, columns, functions and friends. The cache is filled from system tables in the background; readers always get an immutable snapshot and never wait for the server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TableKey

func TableKey(database, table string) string

TableKey is the key of Snapshot.Columns.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache holds the current snapshot and refreshes it on demand.

func NewCache

func NewCache(q Querier) *Cache

NewCache creates a cache that loads through q.

func (*Cache) LastError

func (c *Cache) LastError() error

LastError returns the error of the most recent refresh, if it had one.

func (*Cache) Refresh

func (c *Cache) Refresh(ctx context.Context) error

Refresh reloads the metadata and waits for the result.

func (*Cache) RefreshAsync

func (c *Cache) RefreshAsync()

RefreshAsync starts a background refresh unless one is already running, in which case one more refresh is queued so that the request is not lost.

func (*Cache) RefreshIfOlder

func (c *Cache) RefreshIfOlder(maxAge time.Duration)

RefreshIfOlder starts a background refresh when the snapshot is older than maxAge.

func (*Cache) Snapshot

func (c *Cache) Snapshot() *Snapshot

Snapshot returns the current metadata. It never blocks and never returns nil.

type Column

type Column struct {
	Name string
	Type string
}

Column is a table column.

type Function

type Function struct {
	Name      string
	Aggregate bool
}

Function is a SQL function.

type Querier

type Querier interface {
	QueryStrings(ctx context.Context, sql string) ([][]string, error)
}

Querier runs a metadata query and returns all values as strings.

type Snapshot

type Snapshot struct {
	Databases      []string
	Tables         map[string][]Table  // by database
	Columns        map[string][]Column // by TableKey
	Functions      []Function
	TableFunctions []string
	DataTypes      []string
	Engines        []string
	Formats        []string
	Settings       []string
	Keywords       []string
	// LoadedAt is when the snapshot was fetched; zero for the built-in fallback.
	LoadedAt time.Time
}

Snapshot is an immutable view of the cached metadata.

func (*Snapshot) HasDatabase

func (s *Snapshot) HasDatabase(name string) bool

HasDatabase reports whether a database with this exact name is known.

type Table

type Table struct {
	Database string
	Name     string
	Engine   string
}

Table is a table-like object: a table, view or dictionary.

func (Table) Kind

func (t Table) Kind() string

Kind classifies the table by its engine: "view", "dictionary" or "table".

Jump to

Keyboard shortcuts

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