Documentation
¶
Overview ¶
Package database manages PostgreSQL connections, execution, and special commands.
Index ¶
- Constants
- Variables
- type ChangeDbAction
- type Client
- func (c *Client) Cancel(ctx context.Context) error
- 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, isMulti bool) (Rows, bool, 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 CommandTag
- type ConnInfoAction
- type Connector
- type ExitAction
- type QueryFn
- type Rows
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 ¶
var ( ErrConnectionClosed = errors.New("connection closed unexpectedly") ErrConnectionNotEstablished = errors.New("connection not established") )
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 CommandTag ¶ added in v0.2.1
CommandTag represents the result of a SQL command.
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.
type Rows ¶ added in v0.2.1
type Rows interface {
driver.Rows
// The caller must call Close() when done with the
// result and check the error.
Close() error
// Columns returns the column labels of the current result set.
// The implementation of this method should cache the result so that the
// result does not need to be constructed on each invocation.
Columns() []string
// ColumnTypeDatabaseTypeName returns the database type name
// of the column at the given column index.
ColumnTypeDatabaseTypeName(index int) string
// Tag retrieves the statement tag for the current result set.
Tag() (CommandTag, error)
// Next populates values with the next row of results. []byte values are copied
// so that subsequent calls to Next and Close do not mutate values. This
// makes it slower than theoretically possible but the safety concerns
// (since this is unobvious and unexpected behavior) outweigh.
Next(values []driver.Value) error
// NextResultSet prepares the next result set for reading.
// Returns false if there is no more result set to read.
NextResultSet() (bool, error)
}
Rows describes a result set.