Help us shape the future of Go! Take the 2026 Go Developer Survey

introspect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package introspect provides live database schema introspection capabilities. It discovers tables, columns, constraints, types, and comments from running database instances and populates the parser.Schema model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(base *parser.Schema, p Seedable, files []string) error

Merge implements "both" mode: the introspected schema is seeded into the parser, then file-based DDL is applied on top. The parser's existing duplicate detection handles CREATE TABLE on existing tables (validation error). ALTER TABLE on introspected tables modifies them in place.

After parsing, Merge validates that no duplicate column names with conflicting types exist within any table. This catches the case where ALTER TABLE ADD COLUMN names a column that already exists from the introspected schema with a different type.

Types

type IntrospectionOptions

type IntrospectionOptions struct {
	// Schemas to include. If empty, all non-system schemas are included.
	Schemas []string

	// Schemas to exclude. Applied after include filter.
	ExcludeSchemas []string

	// Tables to include. Supports * (any sequence) and ? (any single char) wildcards.
	// If empty, all tables in included schemas are returned.
	Tables []string

	// Tables to exclude. Supports * and ? wildcards. Applied after include filter.
	ExcludeTables []string
}

IntrospectionOptions controls which schemas and tables are discovered.

type Introspector

type Introspector interface {
	// Name returns the dialect name (e.g., "postgres", "mysql", "sqlite").
	Name() string

	// Introspect connects to the database and populates schema with discovered
	// tables, columns, constraints, types, and comments. The opts parameter
	// controls which schemas and tables are included or excluded.
	Introspect(ctx context.Context, connString string, schema *parser.Schema, opts IntrospectionOptions) error

	// Close releases database resources held by the introspector.
	Close() error
}

Introspector discovers schema elements from a live database connection.

type MySQLIntrospector

type MySQLIntrospector struct {
	// contains filtered or unexported fields
}

MySQLIntrospector discovers schema elements from a live MySQL database.

func NewMySQLIntrospector

func NewMySQLIntrospector() *MySQLIntrospector

NewMySQLIntrospector creates a new MySQL introspector.

func (*MySQLIntrospector) Close

func (mi *MySQLIntrospector) Close() error

Close releases the database connection.

func (*MySQLIntrospector) Introspect

func (mi *MySQLIntrospector) Introspect(ctx context.Context, connString string, schema *parser.Schema, opts IntrospectionOptions) error

Introspect connects to the MySQL database and populates schema with discovered tables, columns, constraints, and comments.

func (*MySQLIntrospector) Name

func (mi *MySQLIntrospector) Name() string

Name returns "mysql".

type PostgresIntrospector

type PostgresIntrospector struct {
	// contains filtered or unexported fields
}

PostgresIntrospector discovers schema elements from a live PostgreSQL database.

func NewPostgresIntrospector

func NewPostgresIntrospector() *PostgresIntrospector

NewPostgresIntrospector creates a new PostgreSQL introspector.

func (*PostgresIntrospector) Close

func (pi *PostgresIntrospector) Close() error

Close releases the database connection.

func (*PostgresIntrospector) Introspect

func (pi *PostgresIntrospector) Introspect(ctx context.Context, connString string, schema *parser.Schema, opts IntrospectionOptions) error

Introspect connects to the PostgreSQL database and populates schema with discovered tables, columns, constraints, enums, composite types, domain types, and comments.

func (*PostgresIntrospector) Name

func (pi *PostgresIntrospector) Name() string

Name returns "postgres".

type SQLiteIntrospector

type SQLiteIntrospector struct {
	// contains filtered or unexported fields
}

SQLiteIntrospector discovers schema elements from a live SQLite database.

func NewSQLiteIntrospector

func NewSQLiteIntrospector() *SQLiteIntrospector

NewSQLiteIntrospector creates a new SQLite introspector.

func (*SQLiteIntrospector) Close

func (si *SQLiteIntrospector) Close() error

Close releases the database connection.

func (*SQLiteIntrospector) Introspect

func (si *SQLiteIntrospector) Introspect(ctx context.Context, connString string, schema *parser.Schema, opts IntrospectionOptions) error

Introspect connects to the SQLite database and populates schema with discovered tables, columns, primary keys, and foreign keys.

func (*SQLiteIntrospector) Name

func (si *SQLiteIntrospector) Name() string

Name returns "sqlite".

type Seedable

type Seedable interface {
	parser.Parser
	Seed(base *parser.Schema)
}

Seedable is a parser that can be pre-populated with an existing schema. This enables "both" mode where introspected tables are loaded before file-based DDL is applied.

Jump to

Keyboard shortcuts

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