introspect

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package introspect reads a live Postgres schema into rig's intermediate representation.

This is the only impure stage of the pipeline. Everything downstream is a pure function of what comes out of here, which is why Read returns a value rather than holding a connection: the rest of the compiler runs from a JSON dump with no database in sight.

Queries go to pg_catalog rather than information_schema. The catalog is less portable and less pleasant to read, but it exposes things the standard views hide — index methods, partial predicates, generated-column kinds, enum sort order — and rig needs all of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(ctx context.Context, q Querier, opt Options) (ir.Schema, error)

Read introspects a schema.

The result is unsorted and unlinked: it says what the database contains and nothing more. Canonicalizing it — ordering, resolving enum types onto columns, classifying join tables — is [compile.Normalize]'s job, so that the same normalization applies whether the schema came from a database or from a file.

Types

type Options

type Options struct {
	// Schema is the Postgres schema to read. Defaults to public.
	Schema string
	// IncludeViews reads views and materialized views alongside base tables.
	IncludeViews bool
}

Options tune a read.

type Querier

type Querier interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

Querier is the subset of pgx a read needs. Taking an interface lets a caller pass a pool, a connection, or a transaction.

Jump to

Keyboard shortcuts

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