Documentation
¶
Overview ¶
Package database manages PostgreSQL connections, execution, and special commands.
Index ¶
- Constants
- type ChangeDbAction
- type Client
- func (c *Client) ChangeDatabase(ctx context.Context, dbName string) error
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Connect(ctx context.Context, connector Connector) error
- func (c *Client) ExecuteQuery(ctx context.Context, query string) (result.Result, error)
- func (c *Client) ExecuteSpecial(ctx context.Context, command string) (pgxspecial.SpecialCommandResult, bool, error)
- func (c *Client) GetDatabase() string
- func (c *Client) GetHost() string
- func (c *Client) GetPort() uint16
- func (c *Client) GetUser() string
- func (c *Client) IsConnected() bool
- func (c *Client) ParsePrompt(str string) string
- func (c *Client) Ping(ctx context.Context) error
- type ConnInfoAction
- type Connector
- type ExitAction
Constants ¶
const ( // Exit is the result kind for quit command actions. Exit pgxspecial.SpecialResultKind = 100 + iota // ChangeDB is the result kind for database switch command actions. ChangeDB // Conninfo is the result kind for connection info command actions. Conninfo )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangeDbAction ¶
type ChangeDbAction struct {
Name string
}
ChangeDbAction carries target database name for \c / \connect commands.
func (ChangeDbAction) ResultKind ¶
func (c ChangeDbAction) ResultKind() pgxspecial.SpecialResultKind
ResultKind returns the special result kind for ChangeDbAction.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides high-level connection management and SQL execution operations.
func (*Client) ChangeDatabase ¶
ChangeDatabase reconnects to the same server with a different database name.
func (*Client) ExecuteQuery ¶
ExecuteQuery runs SQL through the underlying executor and returns typed results.
func (*Client) ExecuteSpecial ¶
func (c *Client) ExecuteSpecial(ctx context.Context, command string) (pgxspecial.SpecialCommandResult, bool, error)
ExecuteSpecial executes a pgxspecial command (for example: \q, \c, \conninfo).
func (*Client) GetDatabase ¶
GetDatabase returns the current database name.
func (*Client) IsConnected ¶
IsConnected reports whether the client currently has an active connection.
func (*Client) ParsePrompt ¶
ParsePrompt resolves prompt placeholders using current connection metadata.
type ConnInfoAction ¶
type ConnInfoAction struct{}
ConnInfoAction indicates that connection info should be displayed.
func (ConnInfoAction) ResultKind ¶
func (g ConnInfoAction) ResultKind() pgxspecial.SpecialResultKind
ResultKind returns the special result kind for ConnInfoAction.
type Connector ¶
type Connector interface {
Connect(ctx context.Context) (*pgx.Conn, error)
UpdatePassword(password string)
Password() string
}
Connector describes how the client obtains and updates a database connection.
func NewPGConnectorFromConnString ¶
NewPGConnectorFromConnString builds a connector from a PostgreSQL connection string.
type ExitAction ¶
type ExitAction struct{}
ExitAction indicates that the REPL should terminate.
func (ExitAction) ResultKind ¶
func (e ExitAction) ResultKind() pgxspecial.SpecialResultKind
ResultKind returns the special result kind for ExitAction.