metadata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFilename = "pathsqlx.yml"

DefaultFilename is the default metadata file that pathsqlx looks for.

Variables

This section is empty.

Functions

func AnalyzeAndSave

func AnalyzeAndSave(db *sql.DB, driverName, path string) error

AnalyzeAndSave is a convenience function that analyzes a database and writes the result to the given path (or DefaultFilename if path is empty).

func ParseForeignKeyDef

func ParseForeignKeyDef(s string) (string, string)

ParseForeignKeyDef splits "table.column" into table and column.

Types

type ForeignKey

type ForeignKey struct {
	FromTable  string
	FromColumn string
	ToTable    string
	ToColumn   string
}

ForeignKey represents a foreign key relationship between two tables.

type ForeignKeyDef

type ForeignKeyDef struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
}

ForeignKeyDef describes a foreign key relationship using "table.column" notation.

type MetadataReader

type MetadataReader interface {
	GetTableMetadata(tableName string) (*TableMetadata, error)
	GetForeignKeys(tableName string) ([]ForeignKey, error)
	GetAllForeignKeys() ([]ForeignKey, error)
	InvalidateCache()
}

MetadataReader is the interface for reading database metadata.

func NewLiveReader

func NewLiveReader(db *sql.DB, driverName string) MetadataReader

NewLiveReader creates a MetadataReader that queries the database at runtime. Supported drivers: "mysql", "postgres", "sqlite3".

type Schema

type Schema struct {
	Tables      map[string]Table  `yaml:"tables"`
	ForeignKeys []ForeignKeyDef   `yaml:"foreign_keys"`
	Paths       map[string]string `yaml:"paths,omitempty"`
}

Schema is the top-level structure of a pathsqlx metadata file.

func Analyze

func Analyze(db *sql.DB, driverName string) (*Schema, error)

Analyze connects to a database and extracts the full schema metadata. Supported drivers: "mysql", "postgres", "sqlite3".

func Load

func Load(path string) (*Schema, error)

Load reads and parses a metadata file from the given path.

func LoadDefault

func LoadDefault() (*Schema, error)

LoadDefault tries to load the default metadata file (pathsqlx.yml) from the current working directory. Returns nil, nil if the file does not exist.

func Parse

func Parse(data []byte) (*Schema, error)

Parse parses raw YAML bytes into a Schema. This is a minimal parser that handles the specific structure of pathsqlx metadata files without requiring a third-party YAML library.

func (*Schema) Marshal

func (s *Schema) Marshal() string

Marshal serializes the schema to YAML. We produce hand-formatted YAML for maximum readability rather than relying on a YAML library.

func (*Schema) NewMetadataReader

func (s *Schema) NewMetadataReader() MetadataReader

NewMetadataReader creates a MetadataReader backed by a Schema loaded from a file. This lets the path inference engine work without a live database connection.

func (*Schema) Save

func (s *Schema) Save(path string) error

Save writes the schema to a YAML file at the given path.

type Table

type Table struct {
	PrimaryKey []string `yaml:"primary_key"`
	Columns    []string `yaml:"columns"`
}

Table describes a single database table.

type TableMetadata

type TableMetadata struct {
	Name        string
	Columns     []string
	PrimaryKeys []string
	ForeignKeys []ForeignKey
}

TableMetadata represents metadata for a database table.

Jump to

Keyboard shortcuts

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