schema

package
v3.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterExcluded

func FilterExcluded(tables, exclude []string) []string

FilterExcluded returns tables with any in the exclude list removed.

func GetDefaultCachePath

func GetDefaultCachePath(baseDir string) string

GetDefaultCachePath returns the default path for schema cache

func ValidateMocks added in v3.27.0

func ValidateMocks(specs []MockSpec, schema map[string][]ColumnInfo, load RowLoader) []error

ValidateMocks checks PostgreSQL expects against a discovered schema. It is pure: a nil loader or a loader error means rows cannot be checked, never a validation error. Unresolvable qualified tables and tables with no columns are skipped.

Types

type AutoDiscoverer

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

AutoDiscoverer implements Discoverer by querying the live database

func NewAutoDiscoverer

func NewAutoDiscoverer(db *sql.DB, dbType string, excludeTables []string) *AutoDiscoverer

NewAutoDiscoverer creates an AutoDiscoverer backed by an open database connection. The caller is responsible for closing the db when done.

func NewAutoDiscovererWithSchemas added in v3.26.1

func NewAutoDiscovererWithSchemas(db *sql.DB, dbType string, excludeTables, schemas []string) *AutoDiscoverer

NewAutoDiscovererWithSchemas is like NewAutoDiscoverer but lets DiscoverSchema cover a list of PostgreSQL schemas. nil or empty means public only.

func (*AutoDiscoverer) DiscoverSchema added in v3.26.1

func (a *AutoDiscoverer) DiscoverSchema() (map[string][]ColumnInfo, error)

DiscoverSchema returns column metadata for every table in the configured schemas. Each table is keyed schema-qualified ("schema.table") and bare ("table"); when a bare name exists in several schemas the first listed wins. For public-only configurations (nil, empty, or ["public"]) only bare keys are emitted.

func (*AutoDiscoverer) DiscoverTables

func (a *AutoDiscoverer) DiscoverTables() ([]string, error)

DiscoverTables queries the database for all user tables and returns their names, excluding any in the ExcludeTables list.

func (*AutoDiscoverer) GetTableColumns

func (a *AutoDiscoverer) GetTableColumns(table string) ([]ColumnInfo, error)

GetTableColumns returns column metadata for the given table.

func (*AutoDiscoverer) LoadCache

func (a *AutoDiscoverer) LoadCache(cacheFile string) error

func (*AutoDiscoverer) SaveCache

func (a *AutoDiscoverer) SaveCache(cacheFile string) error

type ColumnInfo

type ColumnInfo struct {
	Name      string `json:"name"`
	Type      string `json:"type"`
	Nullable  bool   `json:"nullable"`
	IsPrimary bool   `json:"is_primary"`
	Default   string `json:"default,omitempty"`
}

ColumnInfo represents column metadata

type Discoverer

type Discoverer interface {
	DiscoverTables() ([]string, error)
	GetTableColumns(table string) ([]ColumnInfo, error)
	SaveCache(cacheFile string) error
	LoadCache(cacheFile string) error
}

Discoverer defines the interface for schema discovery

func CreateDiscoverer

func CreateDiscoverer(mode string, staticTables []string, excludeTables []string, dbType string, db *sql.DB) (Discoverer, error)

CreateDiscoverer creates a discoverer based on mode and configuration. For "auto" mode, db must be an open database connection; the caller is responsible for closing it.

type MockSpec added in v3.27.0

type MockSpec struct {
	File    string
	Expects []types.ExpectStatement
}

MockSpec is the parsed expects of one spec file, as seen by ValidateMocks.

type NoOpDiscoverer

type NoOpDiscoverer struct{}

NoOpDiscoverer implements Discoverer for when discovery is disabled

func NewNoOpDiscoverer

func NewNoOpDiscoverer() *NoOpDiscoverer

func (*NoOpDiscoverer) DiscoverTables

func (n *NoOpDiscoverer) DiscoverTables() ([]string, error)

func (*NoOpDiscoverer) GetTableColumns

func (n *NoOpDiscoverer) GetTableColumns(table string) ([]ColumnInfo, error)

func (*NoOpDiscoverer) LoadCache

func (n *NoOpDiscoverer) LoadCache(cacheFile string) error

func (*NoOpDiscoverer) SaveCache

func (n *NoOpDiscoverer) SaveCache(cacheFile string) error

type RowLoader added in v3.27.0

type RowLoader func(e types.ExpectStatement) ([]map[string]interface{}, error)

RowLoader returns the rows (column -> value maps) of an expect's RETURNS payload.

type SchemaCache

type SchemaCache struct {
	Tables  map[string][]ColumnInfo `json:"tables"`
	Version string                  `json:"version"`
}

SchemaCache represents cached schema information

type StaticDiscoverer

type StaticDiscoverer struct {
	Tables     []string
	ColumnInfo map[string][]ColumnInfo
}

StaticDiscoverer implements Discoverer for static table lists

func NewStaticDiscoverer

func NewStaticDiscoverer(tables []string) *StaticDiscoverer

func (*StaticDiscoverer) DiscoverTables

func (s *StaticDiscoverer) DiscoverTables() ([]string, error)

func (*StaticDiscoverer) GetTableColumns

func (s *StaticDiscoverer) GetTableColumns(table string) ([]ColumnInfo, error)

func (*StaticDiscoverer) LoadCache

func (s *StaticDiscoverer) LoadCache(cacheFile string) error

func (*StaticDiscoverer) SaveCache

func (s *StaticDiscoverer) SaveCache(cacheFile string) error

func (*StaticDiscoverer) SetTableColumns

func (s *StaticDiscoverer) SetTableColumns(table string, columns []ColumnInfo)

Jump to

Keyboard shortcuts

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