catalog

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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

func LoadFiles(paths []string) (*Catalog, error)

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

func (c *Catalog) Table(name string) (Table, bool)

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

func (c *Catalog) TableNames() []string

TableNames returns the names of all loaded tables in the order they were encountered across the input files.

func (*Catalog) Warnings

func (c *Catalog) Warnings() []string

Warnings returns any non-fatal issues encountered during loading, such as skipped statement types or duplicate table definitions. The catalog is still usable when warnings are present.

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).

type Table

type Table struct {
	Name       string   `json:"name"`
	Columns    []Column `json:"columns"`
	PrimaryKey []string `json:"primary_key"`
	Indexes    []Index  `json:"indexes"`
}

Table is the parsed metadata for a single CREATE TABLE statement.

Jump to

Keyboard shortcuts

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