schema

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package schema provides functionality for caching PostgreSQL objects' metadata eg schema of tables / views, function def etc. It monitors schema changes via notifications and maintains an in-memory representation of tables, columns, and relationships that can be efficiently queried.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(connString string) (*Cache, error)

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) Init

func (c *Cache) Init(ctx context.Context) error

func (*Cache) SchemaHandler

func (c *Cache) SchemaHandler(mux *http.ServeMux, path ...string)

SchemaHandler registers a handler on the provided mux to serve the cached schema

func (*Cache) Snapshot

func (c *Cache) Snapshot() map[string]Table

func (*Cache) Watch

func (c *Cache) Watch() <-chan map[string]Table

type Column

type Column struct {
	Name         string `json:"name"`
	DataType     string `json:"data_type"`
	IsNullable   bool   `json:"is_nullable"`
	IsPrimaryKey bool   `json:"is_primary_key"`
}

type ForeignKey

type ForeignKey struct {
	Column           string `json:"column"`
	ReferencedTable  string `json:"referenced_table"`
	ReferencedColumn string `json:"referenced_column"`
}

type OpenAPIGenerator

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

OpenAPIGenerator generates OpenAPI specs from the schema cache

func NewOpenAPIGenerator

func NewOpenAPIGenerator(cache *Cache, baseURL string, info OpenAPIInfo) *OpenAPIGenerator

NewOpenAPIGenerator creates a new OpenAPI generator

func (*OpenAPIGenerator) GenerateSpecification

func (g *OpenAPIGenerator) GenerateSpecification() map[string]any

GenerateSpecification creates a complete OpenAPI specification

func (*OpenAPIGenerator) ServeHTTP

func (g *OpenAPIGenerator) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler to serve the OpenAPI specification

func (*OpenAPIGenerator) WithSecurity

func (g *OpenAPIGenerator) WithSecurity(config SecurityConfig) *OpenAPIGenerator

WithSecurity configures authentication options

type OpenAPIInfo

type OpenAPIInfo struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Contact     struct {
		Name  string `json:"name,omitempty"`
		Email string `json:"email,omitempty"`
		URL   string `json:"url,omitempty"`
	} `json:"contact,omitzero"`
}

OpenAPIInfo contains API metadata for the OpenAPI specification

type SecurityConfig

type SecurityConfig struct {
	EnableJWT   bool
	EnableBasic bool
}

SecurityConfig defines what authentication methods to include

type Table

type Table struct {
	Schema      string       `json:"schema"`
	Name        string       `json:"name"`
	Type        TableType    `json:"type"`
	Columns     []Column     `json:"columns"`
	PrimaryKeys []string     `json:"primary_keys"`
	ForeignKeys []ForeignKey `json:"foreign_keys"`
	ViewQuery   string       `json:"view_query,omitempty"`
}

type TableType

type TableType string
const (
	TypeTable            TableType = "TABLE"
	TypeView             TableType = "VIEW"
	TypeMaterializedView TableType = "MATERIALIZED VIEW"
)

Jump to

Keyboard shortcuts

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