Documentation
¶
Overview ¶
Package catalog reads schema metadata from the server.
Every query here runs on the connection's control connection, so browsing the schema stays responsive while a large result is still streaming.
Index ¶
- func ColumnKey(schema, table string) string
- func DefaultCachePath() (string, error)
- func QuoteIdentifier(name string) string
- func Schemas(ctx context.Context, conn *db.Conn) ([]string, error)
- func TableDDL(ctx context.Context, conn *db.Conn, schema, table string, isView bool) (string, error)
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) Columns(ctx context.Context, datasource, schema, table string) ([]Column, error)
- func (c *Cache) Names() *NameSource
- func (c *Cache) Save(ctx context.Context, datasource string, snap Snapshot) error
- func (c *Cache) Schemas(ctx context.Context, datasource string) ([]string, error)
- func (c *Cache) SearchTables(ctx context.Context, datasource, needle string, limit int) ([]QualifiedTable, error)
- func (c *Cache) Tables(ctx context.Context, datasource, schema string) ([]Table, error)
- type Column
- type NameSource
- type QualifiedTable
- type Snapshot
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCachePath ¶
DefaultCachePath returns the on-disk location, honouring XDG_STATE_HOME.
func QuoteIdentifier ¶
QuoteIdentifier renders a name as a backtick-quoted MySQL identifier.
func TableDDL ¶
func TableDDL(ctx context.Context, conn *db.Conn, schema, table string, isView bool) (string, error)
TableDDL returns the CREATE statement for a table or view.
It runs on the control connection, alongside the other catalog reads, and deliberately bypasses guard: the statement is read-only and its text is built here rather than typed by the user.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores schema metadata locally.
Completion reads from here rather than from information_schema: on a server with tens of thousands of tables that query takes hundreds of milliseconds, which is far too slow to run on a keystroke.
func (*Cache) Names ¶
func (c *Cache) Names() *NameSource
Names returns a completion-friendly view of the cache.
func (*Cache) Save ¶
Save replaces everything stored for a datasource.
Replacing rather than merging is deliberate: a table dropped on the server has to stop being offered, and a merge would keep suggesting it forever. The whole write is one transaction, so a failure part-way leaves the previous snapshot intact rather than a half-updated one.
func (*Cache) SearchTables ¶
func (c *Cache) SearchTables(ctx context.Context, datasource, needle string, limit int) ([]QualifiedTable, error)
SearchTables finds tables whose name contains the given text, across every schema of a datasource. It backs the go-to-table jump.
type Column ¶
type Column struct {
Name string
Type string
Nullable bool
IsPrimaryKey bool
Default string
Comment string
}
Column is one column of a table.
type NameSource ¶
type NameSource struct {
// contains filtered or unexported fields
}
NameSource adapts the cache to the name-only lookup the completion engine needs.
The engine deals in identifiers, not in schema detail, so this is the whole surface it sees — which is what keeps the engine testable with a map.
type QualifiedTable ¶
QualifiedTable is a table together with the schema holding it.
type Snapshot ¶
Snapshot is a datasource's schema as read from the server.
Tables are keyed by schema name; columns by "schema.table". Maps keep Save a single call rather than an interface the caller has to drive.
func FetchSnapshot ¶
FetchSnapshot reads a datasource's whole schema from the server.
Columns are fetched one query per schema rather than one per table. A server with a few thousand tables would otherwise need a few thousand round trips — minutes through a bastion — and the point of the cache is that completion is ready shortly after connecting, not eventually.