postgres

package
v0.0.0-...-06fb3a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2025 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigSchema = map[string]*schema.Attribute{
	"connection_string":              {Type: schema.TypeString},
	"schema":                         {Type: schema.TypeString},
	"views_to_expose":                {Type: schema.TypeList, Elem: &schema.Attribute{Type: schema.TypeString}},
	"pool_max_conns":                 {Type: schema.TypeInt},
	"pool_min_conns":                 {Type: schema.TypeInt},
	"pool_max_conn_lifetime_minutes": {Type: schema.TypeInt},
	"pool_max_conn_idle_minutes":     {Type: schema.TypeInt},
	"pool_health_check_minutes":      {Type: schema.TypeInt},
}

Functions

func ConfigInstance

func ConfigInstance() interface{}

func IsNotNil

func IsNotNil(input any) bool

func JSONString

func JSONString(data interface{}) (string, error)

JSONString takes a generic interface{} and returns it as a JSON string.

func ListRawResults

func ListRawResults(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error)

func ListTableRecords

func ListTableRecords(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error)

func MakeRawSQLQuery

func MakeRawSQLQuery(ctx context.Context, connectionString, schema string, table string, query string, config PostgresConfig) ([]map[string]any, error)

MakeRawSQLQuery sends a raw SQL query to a remote DB, and returns any results

func MakeSQLQuery

func MakeSQLQuery(ctx context.Context, connectionString, schema string, table string, quals plugin.KeyColumnQualMap, config PostgresConfig) ([]map[string]any, error)

MakeSQLQuery composes a SQL query from a set of quals, sends it to a remote DB, and returns any results

func Plugin

func Plugin(ctx context.Context) *plugin.Plugin

func PluginTables

func PluginTables(ctx context.Context, d *plugin.TableMapData) (map[string]*plugin.Table, error)

func PostgresColTypeToSteampipeColType

func PostgresColTypeToSteampipeColType(ctx context.Context, col Column) proto.ColumnType

func UnmarshalJSON

func UnmarshalJSON(data []byte) (interface{}, error)

UnmarshalJSON unmarshals the input byte slice into a generic interface{}.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides thread-safe caching with TTL

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache creates a new cache with the specified TTL

func (*Cache) Cleanup

func (c *Cache) Cleanup()

Cleanup removes expired entries from the cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves an item from the cache

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set stores an item in the cache with TTL

func (*Cache) Size

func (c *Cache) Size() int

Size returns the number of items in the cache

type CacheEntry

type CacheEntry struct {
	Data      interface{}
	ExpiresAt time.Time
}

CacheEntry represents a cached item with expiration

func (*CacheEntry) IsExpired

func (ce *CacheEntry) IsExpired() bool

IsExpired checks if the cache entry has expired

type CacheManager

type CacheManager struct {
	// contains filtered or unexported fields
}

CacheManager manages different types of caches

func GetCacheManager

func GetCacheManager() *CacheManager

GetCacheManager returns the singleton instance of CacheManager

func (*CacheManager) GetCacheStats

func (cm *CacheManager) GetCacheStats() map[string]int

GetCacheStats returns statistics about all caches

func (*CacheManager) GetCachedQueryResult

func (cm *CacheManager) GetCachedQueryResult(ctx context.Context, connectionString, query string) ([]map[string]any, bool)

GetCachedQueryResult retrieves cached query result

func (*CacheManager) GetCachedViews

func (cm *CacheManager) GetCachedViews(ctx context.Context, connectionString, schema string) ([]View, bool)

GetCachedViews retrieves cached views for a schema

func (*CacheManager) InvalidateQueryCache

func (cm *CacheManager) InvalidateQueryCache()

InvalidateQueryCache removes all cached query results

func (*CacheManager) InvalidateViewsCache

func (cm *CacheManager) InvalidateViewsCache(connectionString, schema string)

InvalidateViewsCache removes cached views for a specific schema

func (*CacheManager) SetCachedQueryResult

func (cm *CacheManager) SetCachedQueryResult(ctx context.Context, connectionString, query string, result []map[string]any)

SetCachedQueryResult stores query result in cache

func (*CacheManager) SetCachedViews

func (cm *CacheManager) SetCachedViews(ctx context.Context, connectionString, schema string, views []View)

SetCachedViews stores views in cache

type Column

type Column struct {
	// contains filtered or unexported fields
}

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

ConnectionManager manages database connection pools for different connection strings

func GetConnectionManager

func GetConnectionManager() *ConnectionManager

GetConnectionManager returns the singleton instance of ConnectionManager

func (*ConnectionManager) CloseAll

func (cm *ConnectionManager) CloseAll()

CloseAll closes all connection pools

func (*ConnectionManager) GetPool

func (cm *ConnectionManager) GetPool(ctx context.Context, connectionString string, postgresConfig PostgresConfig) (*pgxpool.Pool, error)

GetPool returns a connection pool for the given connection string Creates a new pool if one doesn't exist, otherwise returns the existing pool

func (*ConnectionManager) GetPoolStats

func (cm *ConnectionManager) GetPoolStats() map[string]*pgxpool.Stat

GetPoolStats returns statistics for all pools (for monitoring/debugging)

type PostgresConfig

type PostgresConfig struct {
	ConnectionString           *string  `cty:"connection_string"`
	Schema                     *string  `cty:"schema"`
	ViewsToExpose              []string `cty:"views_to_expose"`
	PoolMaxConns               *int     `cty:"pool_max_conns"`
	PoolMinConns               *int     `cty:"pool_min_conns"`
	PoolMaxConnLifetimeMinutes *int     `cty:"pool_max_conn_lifetime_minutes"`
	PoolMaxConnIdleMinutes     *int     `cty:"pool_max_conn_idle_minutes"`
	PoolHealthCheckMinutes     *int     `cty:"pool_health_check_minutes"`
}

func GetConfig

func GetConfig(connection *plugin.Connection) PostgresConfig

GetConfig :: retrieve and cast connection config from query data

func (PostgresConfig) GetConnectionString

func (c PostgresConfig) GetConnectionString() (string, error)

func (PostgresConfig) GetPoolHealthCheckMinutes

func (c PostgresConfig) GetPoolHealthCheckMinutes() int

GetPoolHealthCheckMinutes returns the health check interval in minutes, defaulting to 1 minute

func (PostgresConfig) GetPoolMaxConnIdleMinutes

func (c PostgresConfig) GetPoolMaxConnIdleMinutes() int

GetPoolMaxConnIdleMinutes returns the maximum connection idle time in minutes, defaulting to 1 minute

func (PostgresConfig) GetPoolMaxConnLifetimeMinutes

func (c PostgresConfig) GetPoolMaxConnLifetimeMinutes() int

GetPoolMaxConnLifetimeMinutes returns the maximum connection lifetime in minutes, defaulting to 15 minutes

func (PostgresConfig) GetPoolMaxConns

func (c PostgresConfig) GetPoolMaxConns() int32

GetPoolMaxConns returns the maximum number of connections in the pool, defaulting to 2 for conservative resource usage

func (PostgresConfig) GetPoolMinConns

func (c PostgresConfig) GetPoolMinConns() int32

GetPoolMinConns returns the minimum number of connections to maintain in the pool, defaulting to 0 (on-demand only)

func (PostgresConfig) GetSchema

func (c PostgresConfig) GetSchema() string

GetSchema returns the schema that was configured in the .spc file, if available, and "public" otherwise

func (PostgresConfig) GetViewsToExpose

func (c PostgresConfig) GetViewsToExpose() []string

GetViewsToExpose returns the slice of view patterns that was configured in the .spc file, if set, and ["*"] otherwise (which will expose every view)

func (PostgresConfig) String

func (c PostgresConfig) String() string

type View

type View struct {
	Name    [2]string
	Columns []Column
}

func GetViewsForDBSchema

func GetViewsForDBSchema(ctx context.Context, connectionString, schema string, config PostgresConfig) ([]View, error)

func GetViewsFromPooledConnection

func GetViewsFromPooledConnection(ctx context.Context, conn *pgx.Conn, schema string) ([]View, error)

GetViewsFromPooledConnection gets views using a pooled pgx connection to prevent connection exhaustion OPTIMIZED: Uses a single JOIN query to eliminate N+1 query performance problem

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL