postgres

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discover

func Discover(ctx context.Context, pool *pgxpool.Pool, dbCfg config.DatabaseConfig, store *knowledgemap.Store) error

Discover crawls a PostgreSQL database schema and populates the knowledge map. All existing knowledge map data for the database is cleared and then re-inserted. Schema and table filters from the config are applied during discovery.

Queries run sequentially within a single read-only transaction, with SQLite writes interleaved after each query (pipeline pattern). This is faster than fetching everything first because PG I/O and SQLite writes overlap. Cross-database parallelism is handled by the caller (server.Start).

Types

type PoolManager

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

PoolManager manages connection pools for multiple databases.

func NewPoolManager

func NewPoolManager() *PoolManager

func (*PoolManager) Close

func (pm *PoolManager) Close()

Close shuts down all connection pools.

func (*PoolManager) Connect

func (pm *PoolManager) Connect(ctx context.Context, dbCfg config.DatabaseConfig) error

Connect creates a connection pool for a database config. The connection string includes default_transaction_read_only=on (Tier 2).

func (*PoolManager) Get

func (pm *PoolManager) Get(name string) (*pgxpool.Pool, error)

Get returns a pool for the named database.

type QueryResult

type QueryResult struct {
	Columns       []string                                `json:"columns"`
	Rows          []json.RawMessage                       `json:"rows"`
	Count         int                                     `json:"count"`
	Truncated     bool                                    `json:"truncated"`
	SchemaContext map[string][]knowledgemap.ColumnSummary `json:"schema_context,omitempty"`
}

QueryResult holds the result of a read-only query.

func ReadOnlyQuery

func ReadOnlyQuery(ctx context.Context, pm *PoolManager, dbName, sql string) (*QueryResult, error)

ReadOnlyQuery executes a SQL query with full read-only enforcement:

  • Tier 1: guard.Validate (AST parser via pg_query_go)
  • Tier 2: connection-level default_transaction_read_only=on (set in pool.go)
  • Tier 3: transaction-level BEGIN READ ONLY

Jump to

Keyboard shortcuts

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