Documentation
¶
Overview ¶
Package catalog provides a lightweight in-memory representation of a SQL schema loaded from CREATE TABLE DDL. The primary entry point is Load, which accepts a mix of file paths and raw SQL strings via SchemaSource. LoadFiles is a convenience wrapper for file-only callers.
The catalog is the foundation for Tier 2 (schema-aware) analysis: name resolution, column type lookup, and "did you mean?" suggestions all read from this structure. It is built once, then read-only — no concurrent access is expected, so no synchronization is needed.
Index ¶
Constants ¶
const MaxSchemaFileSize = 100 << 20
MaxSchemaFileSize is the largest schema source Load will accept, whether from a file or raw SQL. Schema DDL is typically small; a 100 MB limit prevents accidental OOM from passing a full database dump.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is the in-memory representation of a SQL schema loaded from one or more DDL files. It holds an ordered list of tables (preserving file order for deterministic output) and a case-insensitive name index for O(1) lookup.
Lifecycle: built once by LoadFiles, then read-only.
func Load ¶
func Load(sources []SchemaSource) (*Catalog, error)
Load parses schema SQL from the given sources and builds a Catalog from the CREATE TABLE statements found. Sources may be file paths or raw SQL strings. Non-CREATE TABLE statements are skipped with a warning. If multiple sources define the same table name, the last definition wins and a warning is recorded.
func LoadFiles ¶
LoadFiles parses the SQL content of each file and builds a Catalog. It is a convenience wrapper around Load for callers that only have file paths.
func (*Catalog) Table ¶
Table returns the table definition with the given name, or false if the catalog contains no such table. Lookup is case-insensitive.
func (*Catalog) TableNames ¶
TableNames returns the names of all loaded tables in the order they were encountered across the input files.
type Column ¶
type Column struct {
Name string `json:"name"`
Type string `json:"type"`
Nullable bool `json:"nullable"`
Default *string `json:"default,omitempty"`
}
Column is one column extracted from a CREATE TABLE definition.
type Index ¶
type Index struct {
Name string `json:"name"`
Columns []string `json:"columns"`
Unique bool `json:"unique"`
}
Index is a secondary index (including UNIQUE constraints) on a table.
type SchemaSource ¶
type SchemaSource struct {
Path string // file to read
SQL string // raw SQL content (used when Path is empty)
Label string // human-readable name for diagnostics
}
SchemaSource represents one source of schema DDL. Either Path or SQL must be set (not both). Label is used in warnings and error messages; when empty it defaults to Path (for file sources) or "<inline SQL>" (for raw SQL sources).