Documentation
¶
Overview ¶
this package contains special command types
Index ¶
- func RegisterCommand(cmdRegistry SpecialCommandRegistry)
- type DescribeTableListResult
- type DescribeTableResult
- type ExtensionVerboseListResult
- type ExtensionVerboseResult
- type RowResult
- type SpecialCommand
- type SpecialCommandRegistry
- type SpecialCommandResult
- type SpecialHandler
- type SpecialResultKind
- type TableFooterMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterCommand ¶
func RegisterCommand(cmdRegistry SpecialCommandRegistry)
RegisterCommand registers a special command and its aliases in the command registry.
The command name and aliases are normalized based on the CaseSensitive flag. If CaseSensitive is false, command keys are stored in lowercase, making lookup case-insensitive.
If multiple aliases are provided, each alias is registered to reference the same command definition.
RegisterCommand does not perform validation for duplicate command names or aliases; later registrations will overwrite existing entries with the same key.
Types ¶
type DescribeTableListResult ¶ added in v0.2.0
type DescribeTableListResult struct {
Results []DescribeTableResult
}
DescribeTableListResult holds multiple DescribeTableResult entries. This is used when multiple tables are described in a single command.
func (DescribeTableListResult) ResultKind ¶ added in v0.2.0
func (DescribeTableListResult) ResultKind() SpecialResultKind
type DescribeTableResult ¶ added in v0.2.0
type DescribeTableResult struct {
Columns []string
Data [][]string
TableMetaData TableFooterMeta
}
DescribeTableResult holds the result of a describe table command. this is not used in any return types directly, but is embedded in DescribeTableListResult.
syntax: \d table_name
type ExtensionVerboseListResult ¶ added in v0.2.0
type ExtensionVerboseListResult struct {
Results []ExtensionVerboseResult
}
ExtensionVerboseListResult holds multiple ExtensionVerboseResult entries. This is used when multiple extensions are described in a single command.
syntax: \dx+ extension_pattern**
func (ExtensionVerboseListResult) ResultKind ¶ added in v0.2.0
func (ExtensionVerboseListResult) ResultKind() SpecialResultKind
type ExtensionVerboseResult ¶ added in v0.2.0
ExtensionVerboseResult holds the result of a single extension verbose command. This is not used in any return types directly, but is embedded in ExtensionVerboseListResult.
type RowResult ¶ added in v0.2.0
RowResult is a wrapper around pgx.Rows to implement SpecialCommandResult. It is used for commands that return a set of rows. For example, \dt to list tables. The caller is responsible for closing the Rows when done.
func (RowResult) ResultKind ¶ added in v0.2.0
func (r RowResult) ResultKind() SpecialResultKind
type SpecialCommand ¶
type SpecialCommand struct {
Cmd string
Syntax string
Description string
Handler SpecialHandler
CaseSensitive bool
}
SpecialCommand represents a parsed and executable special command.
It contains the normalized command name, descriptive metadata, and the handler function invoked during execution. SpecialCommand values are stored internally
type SpecialCommandRegistry ¶
type SpecialCommandRegistry struct {
Cmd string
Alias []string
Syntax string
Description string
Handler SpecialHandler
CaseSensitive bool
}
SpecialCommandRegistry describes a special command registration.
It defines the command name, optional aliases, documentation metadata, and execution handler used when registering commands via RegisterCommand.
type SpecialCommandResult ¶ added in v0.2.0
type SpecialCommandResult interface {
// ResultKind indicates the kind of special result.
ResultKind() SpecialResultKind
}
func ExecuteSpecialCommand ¶
func ExecuteSpecialCommand(ctx context.Context, queryer database.Queryer, specialCommand string) (SpecialCommandResult, bool, error)
ExecuteSpecialCommand parses and executes a special command using the command registry. Syntax: \command[+] [args]
\command - actual special command
\command[+] - actual special command with verbose mode
A special command is identified by a leading backslash (`\`). If the input does not start with a backslash, ExecuteSpecialCommand returns (nil, false, nil) to indicate that the input should be treated as a normal query.
The first whitespace-delimited token is treated as the command name. If the command name ends with a plus sign (`+`), verbose mode is enabled and the suffix is removed before command lookup. The remaining input is passed to the command handler as arguments.
The provided Queryer is used by the command handler to execute any required queries. Return values:
- SpecialCommandResult: the result returned by the command handler, if any
- bool: true if the input was recognized as a special command, even if execution failed
- error: non-nil if the command is unknown or execution fails
An error is returned if the command is not found in the registry or if the command handler returns an error.
type SpecialHandler ¶
type SpecialHandler func(ctx context.Context, db database.Queryer, args string, verbose bool) (SpecialCommandResult, error)
SpecialHandler defines the signature for a special command handler.
A SpecialHandler is invoked with the parsed command arguments and an optional verbose flag. The provided db is used to execute queries as needed.
The returned pgx.Rows, if non-nil, is passed back to the caller for consumption. Any error returned indicates command execution failure.
type SpecialResultKind ¶ added in v0.2.0
type SpecialResultKind int
const ( ResultKindRows SpecialResultKind = iota ResultKindDescribeTable ResultKindExtensionVerbose )
type TableFooterMeta ¶ added in v0.2.0
type TableFooterMeta struct {
}
TableFooterMeta holds the metadata found at the footer of a \d table description this is not used in any return types directly, but is embedded in DescribeTableResult.
Directories
¶
| Path | Synopsis |
|---|---|
|
this package provide the interface to interact with the database
|
this package provide the interface to interact with the database |
|
examples
|
|
|
list_databases
command
|