introspect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name string
	// DataType is the raw type name as returned by the driver
	// (e.g., "int", "enum" for MySQL; "integer", "USER-DEFINED" for Postgres).
	DataType string
	// UDTName names the underlying user-defined type when relevant.
	// On MySQL it is empty (enum labels live in EnumValues).
	// On Postgres it matches the pg_type name when DataType == "USER-DEFINED".
	UDTName string
	// EnumValues holds the labels for an enum column; nil for non-enum columns.
	EnumValues []string
	Kind       Kind
	Nullable   bool
	// Default is the raw column_default expression; nil when the column has
	// no default. A non-nil empty string is a valid value (e.g., MySQL
	// `DEFAULT ”`).
	Default    *string
	IsIdentity bool
	// IsGenerated is true for columns the database computes itself
	// (Postgres GENERATED ALWAYS AS, MySQL VIRTUAL / STORED GENERATED).
	// Writes that target generated columns are rejected by the database
	// (Postgres 428C9, MySQL Error 3105).
	IsGenerated bool
	// IsUnique is set only for single-column UNIQUE constraints.
	IsUnique bool
	// MaxLength is character_maximum_length for length-limited character
	// types (e.g., char, varchar). Zero means unspecified or unlimited;
	// for example, Postgres text reports NULL here and decodes to 0.
	MaxLength int
}

type Driver

type Driver interface {
	Close(ctx context.Context) error
	Introspect(ctx context.Context) (Schema, error)
}

type ForeignKey

type ForeignKey struct {
	Name              string
	Columns           []string
	ReferencedTable   string
	ReferencedColumns []string
}

type Kind

type Kind int

Kind is a driver-agnostic classification of a column's value space, abstracting over the raw type names reported by MySQL or Postgres.

const (
	KindUnknown Kind = iota
	KindBool
	KindInt
	KindFloat
	KindString
	KindUUID
	KindDate
	KindTime
	KindTimestamp
	KindJSON
	KindEnum
	KindBytes
)

func (Kind) String

func (k Kind) String() string

type Schema

type Schema struct {
	Tables []Table
}

func Do

func Do(ctx context.Context, dataSourceName string) (Schema, error)

type Table

type Table struct {
	Name        string
	Columns     []Column
	PrimaryKey  []string
	ForeignKeys []ForeignKey
	// CompositeUniques lists multi-column UNIQUE constraints (single-column
	// UNIQUE constraints are surfaced via Column.IsUnique). Each entry is the
	// ordered list of columns participating in one constraint.
	CompositeUniques [][]string
}

Jump to

Keyboard shortcuts

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