Documentation
¶
Index ¶
- Variables
- func FetchAndCacheSchema(profileName string) error
- func GetContextualSuggestions(query string, cursorPos int, cache *SchemaCache) []string
- func StartSchemaCacheUpdater(interval time.Duration, profileName string, logger *zap.Logger) error
- type AutocompleteHandler
- type AutocompleteService
- func (ac *AutocompleteService) BoostSuggestion(suggestion Suggestion)
- func (ac *AutocompleteService) GetCompletions(sql string, cursorPos int) ([]Suggestion, error)
- func (ac *AutocompleteService) SetMaxSuggestions(max int)
- func (ac *AutocompleteService) Start() error
- func (ac *AutocompleteService) Stop()
- type ColumnMetadata
- type SQLCompletionType
- type SchemaCache
- func (sc *SchemaCache) BoostWord(word string, boostAmount int) bool
- func (sc *SchemaCache) Close() error
- func (sc *SchemaCache) GetAllColumns() ([]string, error)
- func (sc *SchemaCache) GetAllSchemaQualifiedTables() ([]string, error)
- func (sc *SchemaCache) GetAllTables() ([]string, error)
- func (sc *SchemaCache) GetColumns(schemaName, tableName string) ([]ColumnMetadata, error)
- func (sc *SchemaCache) GetFuzzyMatches(prefix string, maxDistance int, limit int) []string
- func (sc *SchemaCache) GetLastRefreshTime() time.Time
- func (sc *SchemaCache) GetSchemas() ([]string, error)
- func (sc *SchemaCache) GetSuggestions(prefix string, limit int) []string
- func (sc *SchemaCache) GetTables(schemaName string) ([]string, error)
- func (sc *SchemaCache) InitializeSQLKeywords() error
- func (sc *SchemaCache) LoadCache() error
- func (sc *SchemaCache) StoreSchema(metadata SchemaMetadata) error
- type SchemaIntrospector
- func (si *SchemaIntrospector) GetColumns(schemaName, tableName string) ([]ColumnMetadata, error)
- func (si *SchemaIntrospector) GetLastRefreshTime() time.Time
- func (si *SchemaIntrospector) GetSchemas() ([]string, error)
- func (si *SchemaIntrospector) GetTables(schemaName string) ([]string, error)
- func (si *SchemaIntrospector) RefreshAll() error
- func (si *SchemaIntrospector) RefreshSchema(schemaName string) error
- func (si *SchemaIntrospector) SetRefreshInterval(interval time.Duration)
- func (si *SchemaIntrospector) StartBackgroundRefresh()
- func (si *SchemaIntrospector) StopBackgroundRefresh()
- type SchemaMetadata
- type Suggestion
- type TableMetadata
- type Trie
- type TrieNode
Constants ¶
This section is empty.
Variables ¶
var CommonSQLKeywords = []string{
"SELECT", "FROM", "WHERE", "GROUP BY", "ORDER BY", "HAVING", "LIMIT",
"JOIN", "LEFT JOIN", "RIGHT JOIN", "INNER JOIN", "FULL JOIN", "CROSS JOIN",
"ON", "AND", "OR", "NOT", "IN", "EXISTS", "BETWEEN", "LIKE", "IS NULL", "IS NOT NULL",
"COUNT", "SUM", "AVG", "MIN", "MAX", "DISTINCT", "AS", "WITH", "UNION", "ALL",
"INSERT", "INTO", "VALUES", "UPDATE", "SET", "DELETE", "CREATE", "TABLE", "VIEW",
"DROP", "ALTER", "ADD", "COLUMN", "DESC", "ASC", "PARTITION BY", "OVER", "CAST",
"CASE", "WHEN", "THEN", "ELSE", "END", "COALESCE", "NULLIF", "EXTRACT", "CURRENT_DATE",
"CURRENT_TIME", "CURRENT_TIMESTAMP", "INTERVAL",
}
Common SQL keywords for autocompletion
Functions ¶
func FetchAndCacheSchema ¶
FetchAndCacheSchema fetches schema metadata for the given profile and caches it
func GetContextualSuggestions ¶
func GetContextualSuggestions(query string, cursorPos int, cache *SchemaCache) []string
GetContextualSuggestions returns suggestions based on the SQL query context It analyzes the query and cursor position to provide more relevant suggestions
Types ¶
type AutocompleteHandler ¶
type AutocompleteHandler struct {
// contains filtered or unexported fields
}
AutocompleteHandler manages SQL autocompletion integration with TUI
func IntegrateWithTUI ¶
func IntegrateWithTUI(app *tview.Application, input *tview.InputField, flex *tview.Flex, profileName string, logger *zap.Logger) (*AutocompleteHandler, error)
IntegrateWithTUI integrates the autocomplete handler with the TUI
func NewAutocompleteHandler ¶
func NewAutocompleteHandler(db *sql.DB, profileName string, app *tview.Application, inputField *tview.InputField, logger *zap.Logger) (*AutocompleteHandler, error)
NewAutocompleteHandler creates a new autocomplete handler for the TUI
func (*AutocompleteHandler) HideSuggestions ¶
func (ah *AutocompleteHandler) HideSuggestions()
HideSuggestions hides the suggestion box
func (*AutocompleteHandler) ProcessKey ¶
func (ah *AutocompleteHandler) ProcessKey(event *tcell.EventKey) bool
ProcessKey handles keyboard input for autocompletion
func (*AutocompleteHandler) ShowSuggestions ¶
func (ah *AutocompleteHandler) ShowSuggestions()
ShowSuggestions displays the suggestion box
func (*AutocompleteHandler) Stop ¶
func (ah *AutocompleteHandler) Stop()
Stop should be called when closing the application
func (*AutocompleteHandler) Update ¶
func (ah *AutocompleteHandler) Update(text string, cursorPos int)
Update should be called when the input text changes
type AutocompleteService ¶
type AutocompleteService struct {
// contains filtered or unexported fields
}
AutocompleteService provides SQL autocompletion functionality
func NewAutocompleteService ¶
func NewAutocompleteService(db *sql.DB, cacheDir string, logger *zap.Logger) (*AutocompleteService, error)
NewAutocompleteService creates a new autocomplete service
func (*AutocompleteService) BoostSuggestion ¶
func (ac *AutocompleteService) BoostSuggestion(suggestion Suggestion)
BoostSuggestion increases the score of a suggestion when it's used
func (*AutocompleteService) GetCompletions ¶
func (ac *AutocompleteService) GetCompletions(sql string, cursorPos int) ([]Suggestion, error)
GetCompletions returns suggestions for the given SQL input and cursor position
func (*AutocompleteService) SetMaxSuggestions ¶
func (ac *AutocompleteService) SetMaxSuggestions(max int)
SetMaxSuggestions sets the maximum number of suggestions to return
func (*AutocompleteService) Start ¶
func (ac *AutocompleteService) Start() error
Start initializes the service and begins background refresh
func (*AutocompleteService) Stop ¶
func (ac *AutocompleteService) Stop()
Stop gracefully shuts down the service
type ColumnMetadata ¶
type ColumnMetadata struct {
Name string `json:"name"`
DataType string `json:"data_type"`
Table string `json:"table"`
Schema string `json:"schema"`
}
ColumnMetadata represents a column's metadata
type SQLCompletionType ¶
type SQLCompletionType int
SQLCompletion types represent different categories of SQL suggestions
const ( Keyword SQLCompletionType = iota SchemaName TableName ColumnName Function )
type SchemaCache ¶
type SchemaCache struct {
// contains filtered or unexported fields
}
SchemaCache manages caching of Trino schema metadata
func NewSchemaCache ¶
func NewSchemaCache(cacheDir string, logger *zap.Logger) (*SchemaCache, error)
NewSchemaCache creates a new schema cache
func (*SchemaCache) BoostWord ¶
func (sc *SchemaCache) BoostWord(word string, boostAmount int) bool
BoostWord increases the score of a word in the trie
func (*SchemaCache) Close ¶
func (sc *SchemaCache) Close() error
Close closes the schema cache and database connection
func (*SchemaCache) GetAllColumns ¶
func (sc *SchemaCache) GetAllColumns() ([]string, error)
GetAllColumns returns all column names from the cache
func (*SchemaCache) GetAllSchemaQualifiedTables ¶
func (sc *SchemaCache) GetAllSchemaQualifiedTables() ([]string, error)
GetAllSchemaQualifiedTables returns all schema-qualified table names (schema.table) from the cache
func (*SchemaCache) GetAllTables ¶
func (sc *SchemaCache) GetAllTables() ([]string, error)
GetAllTables returns all table names from the cache
func (*SchemaCache) GetColumns ¶
func (sc *SchemaCache) GetColumns(schemaName, tableName string) ([]ColumnMetadata, error)
GetColumns returns all column names for a table from the cache
func (*SchemaCache) GetFuzzyMatches ¶
func (sc *SchemaCache) GetFuzzyMatches(prefix string, maxDistance int, limit int) []string
GetFuzzyMatches gets fuzzy-matched suggestions for a prefix
func (*SchemaCache) GetLastRefreshTime ¶
func (sc *SchemaCache) GetLastRefreshTime() time.Time
GetLastRefreshTime returns when the cache was last refreshed
func (*SchemaCache) GetSchemas ¶
func (sc *SchemaCache) GetSchemas() ([]string, error)
GetSchemas returns all schema names from the cache
func (*SchemaCache) GetSuggestions ¶
func (sc *SchemaCache) GetSuggestions(prefix string, limit int) []string
GetSuggestions returns autocomplete suggestions for a given prefix
func (*SchemaCache) GetTables ¶
func (sc *SchemaCache) GetTables(schemaName string) ([]string, error)
GetTables returns all table names for a schema from the cache
func (*SchemaCache) InitializeSQLKeywords ¶
func (sc *SchemaCache) InitializeSQLKeywords() error
Initialize the cache with SQL keywords
func (*SchemaCache) LoadCache ¶
func (sc *SchemaCache) LoadCache() error
LoadCache initializes the trie with data from the cache database
func (*SchemaCache) StoreSchema ¶
func (sc *SchemaCache) StoreSchema(metadata SchemaMetadata) error
StoreSchema stores a schema's metadata in the cache
type SchemaIntrospector ¶
type SchemaIntrospector struct {
// contains filtered or unexported fields
}
SchemaIntrospector fetches schema metadata from Trino in real-time
func NewSchemaIntrospector ¶
func NewSchemaIntrospector(db *sql.DB, cache *SchemaCache, logger *zap.Logger) *SchemaIntrospector
NewSchemaIntrospector creates a new schema introspector
func (*SchemaIntrospector) GetColumns ¶
func (si *SchemaIntrospector) GetColumns(schemaName, tableName string) ([]ColumnMetadata, error)
GetColumns retrieves all column metadata for a specific table
func (*SchemaIntrospector) GetLastRefreshTime ¶
func (si *SchemaIntrospector) GetLastRefreshTime() time.Time
GetLastRefreshTime returns when the last introspection refresh occurred
func (*SchemaIntrospector) GetSchemas ¶
func (si *SchemaIntrospector) GetSchemas() ([]string, error)
GetSchemas retrieves all schema names from Trino
func (*SchemaIntrospector) GetTables ¶
func (si *SchemaIntrospector) GetTables(schemaName string) ([]string, error)
GetTables retrieves all table names for a specific schema
func (*SchemaIntrospector) RefreshAll ¶
func (si *SchemaIntrospector) RefreshAll() error
RefreshAll refreshes all schema metadata
func (*SchemaIntrospector) RefreshSchema ¶
func (si *SchemaIntrospector) RefreshSchema(schemaName string) error
RefreshSchema refreshes metadata for a specific schema
func (*SchemaIntrospector) SetRefreshInterval ¶
func (si *SchemaIntrospector) SetRefreshInterval(interval time.Duration)
SetRefreshInterval sets how often the background refresh occurs
func (*SchemaIntrospector) StartBackgroundRefresh ¶
func (si *SchemaIntrospector) StartBackgroundRefresh()
StartBackgroundRefresh begins a background goroutine that refreshes schema metadata
func (*SchemaIntrospector) StopBackgroundRefresh ¶
func (si *SchemaIntrospector) StopBackgroundRefresh()
StopBackgroundRefresh stops the background refresh goroutine
type SchemaMetadata ¶
type SchemaMetadata struct {
Name string `json:"name"`
Tables []TableMetadata `json:"tables"`
LastUpdate time.Time `json:"last_update"`
}
SchemaMetadata represents a complete schema's metadata
type Suggestion ¶
type Suggestion struct {
Text string
Type SQLCompletionType
Score float64 // Higher is better
Schema string // Only for table/column suggestions
Table string // Only for column suggestions
DetailText string // Additional context/details
}
Suggestion represents a single autocompletion suggestion
type TableMetadata ¶
type TableMetadata struct {
Name string `json:"name"`
Schema string `json:"schema"`
Columns []ColumnMetadata `json:"columns"`
}
TableMetadata represents a table's metadata
type Trie ¶
type Trie struct {
Root *TrieNode
}
Trie is a prefix tree for fast autocompletion lookups
func (*Trie) GetFuzzyMatches ¶
GetFuzzyMatches returns suggestions with fuzzy matching
func (*Trie) GetSuggestions ¶
GetSuggestions returns a list of suggestions that match the given prefix