completer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPgKeywords

func LoadPgKeywords() []string

LoadPgKeywords returns PostgreSQL keyword suggestions used by autocompletion.

Types

type ColumnInfo

type ColumnInfo struct {
	Schema     string
	Table      string
	Column     string
	DataType   string
	HasDefault bool
	Default    *string
}

type ColumnMetadata

type ColumnMetadata struct {
	Name       string
	DataType   string
	ForeignKey []ForeignKey
	Default    *string
	HasDefault bool
}

type Completer

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

func New

func New(logger *slog.Logger) *Completer

New creates a new Completer with an optional logger. If logger is nil, logging will be disabled.

func (*Completer) ExtendColumns

func (c *Completer) ExtendColumns(columns []ColumnInfo, isView bool)

func (*Completer) ExtendDataTypes

func (c *Completer) ExtendDataTypes(dataTypes []DatatypeName)

func (*Completer) ExtendDatabases

func (c *Completer) ExtendDatabases(databases []string)

func (*Completer) ExtendForeignKeys

func (c *Completer) ExtendForeignKeys(foreignKeys []ForeignKey)

func (*Completer) ExtendFunctions

func (c *Completer) ExtendFunctions(funcs []*FunctionMetadata)

func (*Completer) ExtendSchemas

func (c *Completer) ExtendSchemas(schemas []string)

func (*Completer) ExtendTables

func (c *Completer) ExtendTables(tables []Relation)

func (*Completer) GetKeyWords

func (c *Completer) GetKeyWords() []string

GetKeyWords returns the PostgreSQL keywords for autocompletion.

type DatabaseExecutor

type DatabaseExecutor interface {
	// query schema names
	Schemas() ([]string, error)

	// Query table names along with their schema
	Tables() ([]Relation, error)

	// Query view names along with their schema
	Views() ([]Relation, error)

	// Query table column metadata
	TableColumns() ([]ColumnInfo, error)

	// Query view column metadata
	ViewColumns() ([]ColumnInfo, error)

	// Query function metadata
	Functions() ([]*FunctionMetadata, error)

	// Query data type names
	DataTypes() ([]DatatypeName, error)

	// Query foreign key relationships
	ForeignKeys() ([]ForeignKey, error)

	// Query database names
	Databases() ([]string, error)

	// Query the current search path
	SearchPath() ([]string, error)
}

DatabaseExecutor defines the interface for executing database queries to fetch metadata

type DatatypeName

type DatatypeName struct {
	Schema string
	Name   string
}

type ForeignKey

type ForeignKey struct {
	ParentSchema string
	ParentTable  string
	ParentColumn string
	ChildSchema  string
	ChildTable   string
	ChildColumn  string
}

example school.id -> students.school_id parenttable = school parentcolumn = id childtable = students childcolumn = school_id

type FunctionMetadata

type FunctionMetadata struct {
	SchemaName     string
	FuncName       string
	ArgNames       []string
	ArgTypes       []string
	ArgModes       []string
	ArgDefaults    []string
	ReturnType     string
	IsAggregate    bool
	IsWindow       bool
	IsSetReturning bool
	IsExtension    bool
	IsPublic       bool
}

type MetaData

type MetaData struct {
	Databases []string

	SearchPath []string

	Tables map[string]map[string]*TableMetadata // schema -> table -> metadata

	Views map[string]map[string]*TableMetadata // schema -> view -> metadata

	Functions map[string]map[string][]*FunctionMetadata // schema -> functions(overload) -> metadata

	// we are not storing full enum metadata, just the names, suffices for completion
	// reference : pgcli/pgcompleter.py line 288 - 297
	DataTypes map[string]map[string]bool // schema -> datatype -> exists

	// keyword tree: a map mapping keywords to well known following keywords
	// ex: create -> map[table, user, database ...]
	KeyWordsTree map[string]any

	KeyWords []string

	BuiltinFunctions []string

	AllCompletions map[string]bool

	Casing map[string]string

	ReservedWords map[string]bool

	LastRefreshed time.Time
	// contains filtered or unexported fields
}

func NewMetaData

func NewMetaData() *MetaData

type MetaDataRefresher

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

MetaDataRefresher handles asynchronous refreshing of metadata

type RefreshRequest

type RefreshRequest struct {
	// Type of metadata to refresh
	// options: "schemata", "tables", "views", "functions", "datatypes", "etc"
	RefreshTypes []string

	// Callback to invoke after refresh is done
	Callback func(*MetaData)
}

RefreshRequest represents a request to refresh certain types of metadata

type Relation

type Relation struct {
	Schema string
	Name   string
	Kind   RelationKind
}

type RelationKind

type RelationKind string
const (
	RelationKindTable RelationKind = "table"
	RelationKindView  RelationKind = "view"
)

type TableMetadata

type TableMetadata struct {
	Name    string
	Columns map[string]*ColumnMetadata
}

Jump to

Keyboard shortcuts

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