Documentation ¶
Index ¶
- Constants
- Variables
- func AddRootCertToConfig(config *pgconn.Config, certLocation string) error
- func AddSearchPathPrefix(searchPathPrefix []string, searchPath []string) []string
- func BeginFunc(ctx context.Context, db TxBeginner, fn func(*sql.Tx) error) error
- func BuildSearchPathResult(searchPathString string) ([]string, error)
- func CollectOneToStructByName[T any](rows *sql.Rows) (*T, error)
- func CollectToStructByName[T any](rows *sql.Rows) ([]T, error)
- func CreateIntrospectionTables(ctx context.Context, workspaceResources *modconfig.ResourceMaps, tx *sql.Tx) error
- func EnsureInternalSchemaSuffix(searchPath []string) []string
- func ExecuteSystemClientCall(ctx context.Context, conn *sql.Conn, executor SystemClientExecutor) error
- func GetCommentsQueryForPlugin(connectionName string, p map[string]*proto.TableSchema) string
- func GetDeleteConnectionQuery(name string) string
- func GetMissingSchemaFromIsRelationNotFoundError(err error) (string, string, bool)
- func GetUpdateConnectionQuery(connectionName, pluginSchemaName string) string
- func GetUserSearchPath(ctx context.Context, conn *sql.Conn) ([]string, error)
- func IsClientAppName(appName string) bool
- func IsClientSystemAppName(appName string) bool
- func IsRelationNotFoundError(err error) bool
- func IsSchemaNameValid(name string) (bool, string)
- func IsServiceAppName(appName string) bool
- func LoadForeignSchemaNames(ctx context.Context, conn *sql.Conn) ([]string, error)
- func MaxDbConnections() int
- func PgEscapeName(name string) string
- func PgEscapeSearchPath(searchPath []string) []string
- func PgEscapeString(str string) string
- func WaitForConnectionPing(ctx context.Context, connection *sql.Conn, waitOptions ...WaitOption) (err error)
- func WaitForPool(ctx context.Context, db *sql.DB, waitOptions ...WaitOption) (err error)
- func WaitForRecovery(ctx context.Context, connection *sql.Conn, waitOptions ...WaitOption) (err error)
- type ColumnSchema
- type ColumnTag
- type ExecContext
- type InitResult
- type NotificationListener
- type QueryWithArgs
- type SQLFunction
- type SchemaMetadata
- type SystemClientExecutor
- type TableSchema
- type TxBeginner
- 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")
var Functions = []SQLFunction{ { Name: "glob", Params: map[string]string{"input_glob": "text"}, Returns: "text", Language: "plpgsql", Body: ` declare output_pattern text; begin output_pattern = replace(input_glob, '*', '%'); output_pattern = replace(output_pattern, '?', '_'); return output_pattern; end; `, }, { Name: constants.FunctionCacheSet, Params: map[string]string{"command": "text"}, Returns: "void", Language: "plpgsql", Body: ` begin IF command = 'on' THEN INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache','true'); ELSIF command = 'off' THEN INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache','false'); ELSIF command = 'clear' THEN INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache_clear_time',''); ELSE RAISE EXCEPTION 'Unknown value % for set_cache - valid values are on, off and clear.', $1; END IF; end; `, }, { Name: constants.FunctionConnectionCacheClear, Params: map[string]string{"connection": "text"}, Returns: "void", Language: "plpgsql", Body: ` begin INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('connection_cache_clear',connection); end; `, }, { Name: constants.FunctionCacheSetTtl, Params: map[string]string{"duration": "int"}, Returns: "void", Language: "plpgsql", Body: ` begin INSERT INTO steampipe_internal.steampipe_settings("name","value") VALUES ('cache_ttl',duration); end; `, }, }
Functions is a list of SQLFunction objects that are installed in the db 'steampipe_internal' schema startup
Functions ¶
func AddRootCertToConfig ¶
func AddSearchPathPrefix ¶
func BuildSearchPathResult ¶
func ExecuteSystemClientCall ¶
func ExecuteSystemClientCall(ctx context.Context, conn *sql.Conn, executor SystemClientExecutor) error
ExecuteSystemClientCall creates a transaction and sets the application_name to the one used by the system client, executes the callback and sets the application name back to the client app name
func GetCommentsQueryForPlugin ¶
func GetCommentsQueryForPlugin(connectionName string, p map[string]*proto.TableSchema) string
func GetUserSearchPath ¶
TODO:: KAI :: we need to fix this this is going to be referred to from steampipe code in the future and
func IsClientAppName ¶
TODO think about app specific stuff here
func IsClientSystemAppName ¶
func IsRelationNotFoundError ¶
func IsSchemaNameValid ¶
IsSchemaNameValid verifies that the given string is a valid pgsql schema name
func IsServiceAppName ¶
func LoadForeignSchemaNames ¶
func MaxDbConnections ¶
func MaxDbConnections() int
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 WaitForConnectionPing ¶
func WaitForConnectionPing(ctx context.Context, connection *sql.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 ¶
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 ¶
func WaitForRecovery(ctx context.Context, connection *sql.Conn, waitOptions ...WaitOption) (err error)
WaitForRecovery returns an error (ErrRecoveryMode) if the service stays in recovery mode for more than constants.DBRecoveryWaitTimeout
Types ¶
type ColumnSchema ¶
type ColumnSchema struct { ID string Name string NotNull bool Type string Default string Description string }
ColumnSchema contains the details of a single column in a table
type ColumnTag ¶
ColumnTag is a struct used to display column info in introspection tables
func NewColumnTag ¶
func NewColumnTag(field reflect.StructField) (*ColumnTag, bool)
type ExecContext ¶
type InitResult ¶
type InitResult struct { error_helpers.ErrorAndWarnings 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(messages ...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
func (*InitResult) Merge ¶
func (r *InitResult) Merge(other InitResult)
type NotificationListener ¶
type NotificationListener struct {
// contains filtered or unexported fields
}
func NewNotificationListener ¶
func NewNotificationListener(ctx context.Context, conn *pgx.Conn) (*NotificationListener, error)
func (*NotificationListener) RegisterListener ¶
func (c *NotificationListener) RegisterListener(onNotification func(*pgconn.Notification))
func (*NotificationListener) Stop ¶
func (c *NotificationListener) Stop(ctx context.Context)
type QueryWithArgs ¶
type SQLFunction ¶
type SQLFunction struct { Name string Params map[string]string Returns string Body string Language string }
SQLFunction is a struct for an sqlFunc
type SchemaMetadata ¶
type SchemaMetadata struct { // map {schemaname, {map {tablename -> tableschema}} Schemas map[string]map[string]TableSchema // the name of the temporary schema TemporarySchemaName string }
SchemaMetadata is a struct to represent the schema of the database
func LoadSchemaMetadata ¶
func NewSchemaMetadata ¶
func NewSchemaMetadata() *SchemaMetadata
func (*SchemaMetadata) GetSchemas ¶
func (m *SchemaMetadata) GetSchemas() []string
GetSchemas returns all foreign schema names
func (*SchemaMetadata) GetTablesInSchema ¶
func (m *SchemaMetadata) GetTablesInSchema(schemaName string) map[string]struct{}
GetTablesInSchema returns a lookup of all foreign tables in a given foreign schema
type SystemClientExecutor ¶
SystemClientExecutor is the executor function that is called within a transaction make sure that by the time the executor finishes execution, the connection is freed otherwise we will get a `conn is busy` error
type TableSchema ¶
type TableSchema struct { // map columnName -> columnSchema Columns map[string]ColumnSchema Name string FullName string Schema string Description string }
TableSchema contains the details of a single table in the schema
type TxBeginner ¶
type WaitOption ¶
type WaitOption func(w *waitConfig)
func WithRetryInterval ¶
func WithRetryInterval(d time.Duration) WaitOption
func WithTimeout ¶
func WithTimeout(d time.Duration) WaitOption
Source Files ¶
- appname.go
- column_tag.go
- errors.go
- functions.go
- init_result.go
- interaces.go
- introspection_tables.go
- max_connections.go
- notification_cache.go
- postgres.go
- query_with_args.go
- scan_to_struct.go
- schema.go
- schema_metadata.go
- search_path.go
- session_system.go
- sql_connections.go
- sql_function.go
- tls_config.go
- wait_connection.go