introspect

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnToFieldType

func ColumnToFieldType(dataType string) admin.FieldType

ColumnToFieldType maps a PostgreSQL data_type string to the closest admin.FieldType. The mapping is intentionally conservative: types that need domain knowledge (e.g. an "integer" that represents money) should be overridden after generation.

func IsLikelyEmail

func IsLikelyEmail(col Column) bool

IsLikelyEmail returns true when a column name strongly suggests an email address.

func IsLikelyPassword

func IsLikelyPassword(col Column) bool

IsLikelyPassword returns true when a column name strongly suggests a stored password.

func IsLikelyPrimaryKey

func IsLikelyPrimaryKey(col Column) bool

IsLikelyPrimaryKey returns true when the column name and type look like a primary key.

func IsLikelyTimestamp

func IsLikelyTimestamp(col Column) bool

IsLikelyTimestamp returns true when a column appears to be a timestamp field.

func IsSearchable

func IsSearchable(col Column) bool

IsSearchable returns true for column types that are reasonable to full-text search.

func IsSortable

func IsSortable(col Column) bool

IsSortable returns true for column types that support ORDER BY sensibly.

func SuggestFieldType

func SuggestFieldType(col Column) admin.FieldType

SuggestFieldType returns a more precise FieldType by considering both the PostgreSQL data type and the column name heuristics.

Types

type Column

type Column struct {
	Name       string `json:"name"`
	DataType   string `json:"data_type"`
	Nullable   bool   `json:"nullable"`
	Default    string `json:"default,omitempty"`
	IsIdentity bool   `json:"is_identity"`
}

Column represents a single column in a table.

type Schema

type Schema struct {
	Tables []Table `json:"tables"`
}

Schema holds the introspected PostgreSQL schema.

func Load

func Load(ctx context.Context, databaseURL string) (Schema, error)

Load connects to a PostgreSQL database and introspects all user tables, returning a Schema containing their columns and primary-key information.

type Table

type Table struct {
	Schema     string   `json:"schema"`
	Name       string   `json:"name"`
	Columns    []Column `json:"columns"`
	PrimaryKey []string `json:"primary_key"`
}

Table represents a single database table.

Jump to

Keyboard shortcuts

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