Documentation ¶
Index ¶
- Constants
- func IsConnectionString(connString string) bool
- type DbClient
- func (c *DbClient) Close(context.Context) error
- func (c *DbClient) Execute(ctx context.Context, query string, args ...any) (*queryresult.Result, error)
- func (c *DbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*queryresult.SyncQueryResult, error)
- func (c *DbClient) GetConnectionString() string
- func (c *DbClient) GetCustomSearchPath() []string
- func (c *DbClient) GetRequiredSessionSearchPath() []string
- func (c *DbClient) LoadUserSearchPath(ctx context.Context) error
- func (c *DbClient) LoadUserSearchPathForConnection(ctx context.Context, connection *sql.Conn) error
- func (c *DbClient) RegisterNotificationListener(func(notification *pgconn.Notification))
- func (c *DbClient) ResetPools(ctx context.Context)
- func (c *DbClient) SetRequiredSessionSearchPath(ctx context.Context) error
- func (c *DbClient) StartQuery(ctx context.Context, dbConn *sql.Conn, query string, args ...any) (rows *sql.Rows, err error)
Constants ¶
const ( MaxConnLifeTime = 10 * time.Minute MaxConnIdleTime = 1 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func IsConnectionString ¶
Types ¶
type DbClient ¶
type DbClient struct { // connection UserPool for user initiated queries UserPool *sql.DB // connection used to run system/plumbing queries (connection state, server settings) ManagementPool *sql.DB // TODO KAI new hook <TIMING> BeforeExecuteHook func(context.Context, *sql.Conn) error // if a custom search path or a prefix is used, store it here CustomSearchPath []string SearchPathPrefix []string // the default user search path UserSearchPath []string // contains filtered or unexported fields }
DbClient wraps over `sql.DB` and gives an interface to the database
func NewDbClient ¶
func (*DbClient) Execute ¶
func (c *DbClient) Execute(ctx context.Context, query string, args ...any) (*queryresult.Result, error)
execute the query in the given Context NOTE: The returned Result MUST be fully read - otherwise the connection will block and will prevent further communication
func (*DbClient) ExecuteSync ¶
func (c *DbClient) ExecuteSync(ctx context.Context, query string, args ...any) (*queryresult.SyncQueryResult, error)
execute a query against this client and wait for the result
func (*DbClient) GetConnectionString ¶
func (*DbClient) GetCustomSearchPath ¶
func (*DbClient) GetRequiredSessionSearchPath ¶
GetRequiredSessionSearchPath implements Client
func (*DbClient) LoadUserSearchPath ¶
func (*DbClient) LoadUserSearchPathForConnection ¶
func (*DbClient) RegisterNotificationListener ¶
func (c *DbClient) RegisterNotificationListener(func(notification *pgconn.Notification))
RegisterNotificationListener has an empty implementation NOTE: we do not (currently) support notifications from remote connections
func (*DbClient) ResetPools ¶
TODO KAI STEAMPIPE ONLY <MISC> Unimplemented (sql.DB does not have a mechanism to reset pools) - refreshDbClient terminates the current connection and opens up a new connection to the service.
func (*DbClient) SetRequiredSessionSearchPath ¶
SetRequiredSessionSearchPath checks if either a search-path or search-path-prefix is set in config, and if so, set the search path (otherwise fall back to user search path) this just sets the required search path for this client - when creating a database session, we will actually set the searchPath
func (*DbClient) StartQuery ¶
func (c *DbClient) StartQuery(ctx context.Context, dbConn *sql.Conn, query string, args ...any) (rows *sql.Rows, err error)
StartQuery runs query in a goroutine, so we can check for cancellation in case the client becomes unresponsive and does not respect context cancellation