db

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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

type DatabaseSchema struct {
	Name   string
	Tables []Table
}

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 Index

type Index struct {
	Name      string
	TableName string
	Columns   []string
	IsUnique  bool
	IsPrimary bool
}

Index describes a table index 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.

type Table

type Table struct {
	Schema      string
	Name        string
	Columns     []Column
	Indexes     []Index
	ForeignKeys []ForeignKey
}

Table describes a database table with its columns, indexes, and foreign keys as read from a live database.

Jump to

Keyboard shortcuts

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