Documentation
¶
Overview ¶
Package db provides types and interfaces for live database schema introspection. Use dialect-specific loaders from pkg/schema/postgres, pkg/schema/mysql, or pkg/schema/sqlite to connect to a live database and retrieve structured schema metadata (tables, columns, indexes, foreign keys).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
Name string
OrdinalPos int
DataType string
IsNullable bool
DefaultValue *string
MaxLength *int
Precision *int
Scale *int
IsPrimary bool
IsUnique bool
}
Column describes a single column in a table as read from a live database.
type DatabaseSchema ¶
DatabaseSchema is the top-level result from live schema introspection.
type ForeignKey ¶
type ForeignKey struct {
Name string
TableName string
Columns []string
RefTable string
RefColumns []string
OnDelete string
OnUpdate string
}
ForeignKey describes a foreign key constraint as read from a live database.
type Loader ¶
type Loader interface {
// Load returns the full schema for all user tables in the database.
// schemaName may be empty to use the database default.
Load(db *sql.DB, schemaName string) (*DatabaseSchema, error)
// LoadTable returns schema for a single named table.
LoadTable(db *sql.DB, schemaName, tableName string) (*Table, error)
}
Loader connects to a live database and reads its schema metadata. Dialect-specific implementations are provided in pkg/schema/postgres, pkg/schema/mysql, and pkg/schema/sqlite.