{"modulePath":"github.com/mevdschee/pathsqlx","version":"v0.2.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package metadata\n\n## Constants\n\n```go\nconst DefaultFilename = \"pathsqlx.yml\"\n```\nDefaultFilename is the default metadata file that pathsqlx looks for.\n\n## Functions\n\n```go\nfunc AnalyzeAndSave(db *sql.DB, driverName, path string) error\n```\nAnalyzeAndSave is a convenience function that analyzes a database and writes the result to the given path (or DefaultFilename if path is empty).\n\n```go\nfunc ParseForeignKeyDef(s string) (string, string)\n```\nParseForeignKeyDef splits \"table.column\" into table and column.\n\n## Types\n\n```go\ntype ForeignKey struct {\n\tFromTable  string\n\tFromColumn string\n\tToTable    string\n\tToColumn   string\n}\n```\nForeignKey represents a foreign key relationship between two tables.\n\n```go\ntype ForeignKeyDef struct {\n\tFrom string `yaml:\"from\"`\n\tTo   string `yaml:\"to\"`\n}\n```\nForeignKeyDef describes a foreign key relationship using \"table.column\" notation.\n\n```go\ntype MetadataReader interface {\n\tGetTableMetadata(tableName string) (*TableMetadata, error)\n\tGetForeignKeys(tableName string) ([]ForeignKey, error)\n\tGetAllForeignKeys() ([]ForeignKey, error)\n\tInvalidateCache()\n}\n```\nMetadataReader is the interface for reading database metadata.\n\n```go\nfunc NewLiveReader(db *sql.DB, driverName string) MetadataReader\n```\nNewLiveReader creates a MetadataReader that queries the database at runtime. Supported drivers: \"mysql\", \"postgres\", \"sqlite3\".\n\n```go\ntype Schema struct {\n\tTables      map[string]Table  `yaml:\"tables\"`\n\tForeignKeys []ForeignKeyDef   `yaml:\"foreign_keys\"`\n\tPaths       map[string]string `yaml:\"paths,omitempty\"`\n}\n```\nSchema is the top-level structure of a pathsqlx metadata file.\n\n```go\nfunc Analyze(db *sql.DB, driverName string) (*Schema, error)\n```\nAnalyze connects to a database and extracts the full schema metadata. Supported drivers: \"mysql\", \"postgres\", \"sqlite3\".\n\n```go\nfunc Load(path string) (*Schema, error)\n```\nLoad reads and parses a metadata file from the given path.\n\n```go\nfunc LoadDefault() (*Schema, error)\n```\nLoadDefault tries to load the default metadata file (pathsqlx.yml) from the current working directory. Returns nil, nil if the file does not exist.\n\n```go\nfunc Parse(data []byte) (*Schema, error)\n```\nParse 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.\n\n```go\nfunc (s *Schema) Marshal() string\n```\nMarshal serializes the schema to YAML. We produce hand-formatted YAML for maximum readability rather than relying on a YAML library.\n\n```go\nfunc (s *Schema) NewMetadataReader() MetadataReader\n```\nNewMetadataReader creates a MetadataReader backed by a Schema loaded from a file. This lets the path inference engine work without a live database connection.\n\n```go\nfunc (s *Schema) Save(path string) error\n```\nSave writes the schema to a YAML file at the given path.\n\n```go\ntype Table struct {\n\tPrimaryKey []string `yaml:\"primary_key\"`\n\tColumns    []string `yaml:\"columns\"`\n}\n```\nTable describes a single database table.\n\n```go\ntype TableMetadata struct {\n\tName        string\n\tColumns     []string\n\tPrimaryKeys []string\n\tForeignKeys []ForeignKey\n}\n```\nTableMetadata represents metadata for a database table.\n\n","path":"github.com/mevdschee/pathsqlx/metadata","name":"metadata","synopsis":"","isRedistributable":true}
