model

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package model defines normalized schema catalog types produced by the parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortColumns

func SortColumns(cols []*Column)

SortColumns provides deterministic ordering of columns by name.

func SortForeignKeys

func SortForeignKeys(keys []*ForeignKey)

SortForeignKeys provides deterministic ordering of foreign key constraints by name then reference.

func SortIndexes

func SortIndexes(idxs []*Index)

SortIndexes provides deterministic ordering of indexes by name.

func SortUniqueKeys

func SortUniqueKeys(keys []*UniqueKey)

SortUniqueKeys provides deterministic ordering of unique constraints by name then columns.

Types

type Catalog

type Catalog struct {
	Tables     map[string]*Table
	Views      map[string]*View
	Enums      map[string]*Enum
	Domains    map[string]*Domain
	Composites map[string]*Composite
}

Catalog represents the collection of tables and views discovered in DDL files.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog constructs a catalog with initialized maps.

type Column

type Column struct {
	Name       string
	Type       string
	NotNull    bool
	Default    *Value
	References *ForeignKeyRef
	Span       tokenizer.Span
}

Column describes a table column with optional inline constraints.

type Composite added in v0.11.0

type Composite struct {
	Name   string
	Fields []CompositeField
	Span   tokenizer.Span
}

Composite represents a CREATE TYPE ... AS (...) definition (a PostgreSQL composite type). Each composite maps to a generated Go struct whose fields mirror the declared composite fields in declaration order.

type CompositeField added in v0.11.0

type CompositeField struct {
	Name string
	Type string
}

CompositeField is a single field of a composite type: its declared name and the ordinary SQL type token used to resolve its generated Go field type.

type Domain added in v0.5.0

type Domain struct {
	Name        string
	BaseType    string
	Constraints []*DomainConstraint
	Span        tokenizer.Span
}

Domain represents a CREATE DOMAIN definition.

type DomainConstraint added in v0.5.0

type DomainConstraint struct {
	Name string
	Type string // "check", "not_null", "default"
	Expr string
	Span tokenizer.Span
}

DomainConstraint represents a constraint on a domain.

type Enum added in v0.5.0

type Enum struct {
	Name   string
	Values []string
	Span   tokenizer.Span
}

Enum represents a CREATE TYPE ... AS ENUM definition.

type ForeignKey

type ForeignKey struct {
	Name    string
	Columns []string
	Ref     ForeignKeyRef
	Span    tokenizer.Span
}

ForeignKey models a FOREIGN KEY constraint referencing another table.

type ForeignKeyRef

type ForeignKeyRef struct {
	Table   string
	Columns []string
	Span    tokenizer.Span
}

ForeignKeyRef describes the referenced table and column set for a foreign key.

type Index

type Index struct {
	Name    string
	Unique  bool
	Columns []string
	Span    tokenizer.Span
}

Index describes a CREATE INDEX or CREATE UNIQUE INDEX statement targeting a table.

type PrimaryKey

type PrimaryKey struct {
	Name    string
	Columns []string
	Span    tokenizer.Span
}

PrimaryKey captures a table's primary key declaration.

type Table

type Table struct {
	Name         string
	Doc          string
	Columns      []*Column
	PrimaryKey   *PrimaryKey
	UniqueKeys   []*UniqueKey
	ForeignKeys  []*ForeignKey
	Indexes      []*Index
	WithoutRowID bool
	Strict       bool
	Span         tokenizer.Span
}

Table models a SQLite table definition with associated constraints.

type UniqueKey

type UniqueKey struct {
	Name    string
	Columns []string
	Span    tokenizer.Span
}

UniqueKey captures a UNIQUE constraint across one or more columns.

type Value

type Value struct {
	Kind ValueKind
	Text string
	Span tokenizer.Span
}

Value stores the raw literal used in expressions such as DEFAULT clauses.

type ValueKind

type ValueKind int

ValueKind identifies the literal kind stored in a Value.

const (
	// ValueKindUnknown is used when the literal kind cannot be determined.
	ValueKindUnknown ValueKind = iota
	// ValueKindNumber represents numeric literals.
	ValueKindNumber
	// ValueKindString represents single-quoted string literals.
	ValueKindString
	// ValueKindBlob represents blob literals of the form X'...'.
	ValueKindBlob
	// ValueKindKeyword represents keywords used as literal defaults (e.g. CURRENT_TIMESTAMP).
	ValueKindKeyword
)

type View

type View struct {
	Name string
	Doc  string
	SQL  string
	Span tokenizer.Span
}

View represents a CREATE VIEW statement along with the raw SQL body.

Jump to

Keyboard shortcuts

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