Documentation
¶
Index ¶
- Constants
- Variables
- func AddRootCertToConfig(config *pgconn.Config, certLocation string) error
- func BuildSchemaMetadata(rows pgx.Rows) (_ *schema.Metadata, err error)
- func CreateIntrospectionTables(ctx context.Context, workspaceResources *modconfig.ResourceMaps, ...) error
- func ExecuteQuery(ctx context.Context, client Client, queryString string, args ...any) (*queryresult.ResultStreamer, error)
- func PgEscapeName(name string) string
- func PgEscapeSearchPath(searchPath []string) []string
- func PgEscapeString(str string) string
- func WaitForConnection(ctx context.Context, connStr string, options ...WaitOption) (conn *pgx.Conn, err error)
- func WaitForConnectionPing(ctx context.Context, connection *pgx.Conn, waitOptions ...WaitOption) (err error)
- func WaitForPool(ctx context.Context, db *pgxpool.Pool, waitOptions ...WaitOption) (err error)
- func WaitForRecovery(ctx context.Context, connection *pgx.Conn, waitOptions ...WaitOption) (err error)
- type AcquireSessionResult
- type Client
- type ColumnTag
- type DatabaseSession
- type InitResult
- type WaitOption
Constants ¶
const TagColumn = "column"
TagColumn is the tag used to specify the column name and type in the introspection tables
Variables ¶
var ErrServiceInRecoveryMode = errors.New("service is in recovery mode")
Functions ¶
func AddRootCertToConfig ¶ added in v0.17.0
func ExecuteQuery ¶
func ExecuteQuery(ctx context.Context, client Client, queryString string, args ...any) (*queryresult.ResultStreamer, error)
ExecuteQuery executes a single query. If shutdownAfterCompletion is true, shutdown the client after completion
func PgEscapeName ¶
PgEscapeName escapes strings which will be usaed for Podsdtgres object identifiers (table names, column names, schema names)
func PgEscapeSearchPath ¶
PgEscapeSearchPath applies postgres escaping to search path and remove whitespace
func PgEscapeString ¶
PgEscapeString escapes strings which are to be inserted use a custom escape tag to avoid chance of clash with the escaped text https://medium.com/@lnishada/postgres-dollar-quoting-6d23e4f186ec
func WaitForConnection ¶
func WaitForConnectionPing ¶ added in v0.19.0
func WaitForConnectionPing(ctx context.Context, connection *pgx.Conn, waitOptions ...WaitOption) (err error)
WaitForConnectionPing PINGs the DB - retrying after a backoff of constants.ServicePingInterval - but only for constants.DBConnectionTimeout returns the error from the database if the dbClient does not respond successfully after a timeout
func WaitForPool ¶ added in v0.17.0
WaitForPool waits for the db to start accepting connections and returns true returns false if the dbClient does not start within a stipulated time,
func WaitForRecovery ¶ added in v0.19.0
func WaitForRecovery(ctx context.Context, connection *pgx.Conn, waitOptions ...WaitOption) (err error)
WaitForRecovery returns an error (ErrRecoveryMode) if the service stays in recovery mode for more than constants.DBRecoveryWaitTimeout
Types ¶
type AcquireSessionResult ¶
type AcquireSessionResult struct {
Session *DatabaseSession
Error error
Warnings []string
}
type Client ¶
type Client interface {
Close(ctx context.Context) error
ForeignSchemaNames() []string
AllSchemaNames() []string
LoadSchemaNames(ctx context.Context) error
GetCurrentSearchPath(context.Context) ([]string, error)
GetCurrentSearchPathForDbConnection(context.Context, *sql.Conn) ([]string, error)
SetRequiredSessionSearchPath(context.Context) error
GetRequiredSessionSearchPath() []string
ConstructSearchPath(context.Context, []string, []string) ([]string, error)
AcquireSession(context.Context) *AcquireSessionResult
ExecuteSync(context.Context, string, ...any) (*queryresult.SyncQueryResult, error)
Execute(context.Context, string, ...any) (*queryresult.Result, error)
ExecuteSyncInSession(context.Context, *DatabaseSession, string, ...any) (*queryresult.SyncQueryResult, error)
ExecuteInSession(context.Context, *DatabaseSession, func(), string, ...any) (*queryresult.Result, error)
CacheOn(context.Context) error
CacheOff(context.Context) error
CacheClear(context.Context) error
RefreshSessions(ctx context.Context) *AcquireSessionResult
GetSchemaFromDB(context.Context) (*schema.Metadata, error)
// remote client will have empty implementation
RefreshConnectionAndSearchPaths(context.Context, ...string) *steampipeconfig.RefreshConnectionResult
}
type DatabaseSession ¶
type DatabaseSession struct {
BackendPid uint32 `json:"backend_pid"`
UsedCount int `json:"used"`
LastUsed time.Time `json:"last_used"`
SearchPath []string `json:"-"`
Initialized bool `json:"-"`
// this gets rewritten, since the database/sql gives back a new instance everytime
Connection *pgxpool.Conn `json:"-"`
// the id of the last scan metadata retrieved
ScanMetadataMaxId int64 `json:"-"`
}
DatabaseSession wraps over the raw database/sql.Conn and also allows for retaining useful instrumentation
func NewDBSession ¶
func NewDBSession(backendPid uint32) *DatabaseSession
func (*DatabaseSession) Close ¶
func (s *DatabaseSession) Close(waitForCleanup bool)
func (*DatabaseSession) UpdateUsage ¶
func (s *DatabaseSession) UpdateUsage()
UpdateUsage updates the UsedCount of the DatabaseSession and also the lastUsed time
type InitResult ¶
type InitResult struct {
Error error
Warnings []string
Messages []string
// allow overriding of the display functions
DisplayMessage func(ctx context.Context, m string)
DisplayWarning func(ctx context.Context, w string)
}
func (*InitResult) AddMessage ¶
func (r *InitResult) AddMessage(message string)
func (*InitResult) AddWarnings ¶
func (r *InitResult) AddWarnings(warnings ...string)
func (*InitResult) DisplayMessages ¶
func (r *InitResult) DisplayMessages()
func (*InitResult) HasMessages ¶
func (r *InitResult) HasMessages() bool
type WaitOption ¶ added in v0.19.0
type WaitOption func(w *waitConfig)
func WithRetryInterval ¶ added in v0.19.0
func WithRetryInterval(d time.Duration) WaitOption
func WithTimeout ¶ added in v0.19.0
func WithTimeout(d time.Duration) WaitOption