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

sqlinspect

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sqlinspect provides reusable, read-only SQL catalog inspection.

Index

Constants

View Source
const (
	DefaultMaxRelations       = 5000
	DefaultMaxColumns         = 50000
	DefaultMaxMetadata        = 50000
	DefaultMaxRoutines        = 2000
	DefaultMaxDefinitionBytes = 4 * 1024 * 1024
)

Variables

This section is empty.

Functions

func ListDatabases

func ListDatabases(ctx context.Context, db *sql.DB, driver string) (_ []string, returnErr error)

ListDatabases returns databases accessible to the current connection user.

func NormalizeDriver

func NormalizeDriver(driver string) string

NormalizeDriver resolves supported driver aliases to their catalog backend.

func ValidateDriver

func ValidateDriver(driver string) error

ValidateDriver rejects backends without catalog queries.

Types

type Catalog

type Catalog struct {
	Driver         string                         `json:"driver"`
	Database       string                         `json:"database,omitempty"`
	Capabilities   connection.BackendCapabilities `json:"capabilities"`
	Databases      []string                       `json:"databases,omitempty"`
	DefaultSchema  string                         `json:"defaultSchema,omitempty"`
	Schemas        []Schema                       `json:"schemas"`
	Truncated      bool                           `json:"truncated,omitempty"`
	TruncateReason string                         `json:"truncateReason,omitempty"`
}

func Inspect

func Inspect(ctx context.Context, db *sql.DB, driver string, limits Limits) (_ Catalog, returnErr error)

inspect reads only the current database. Querying schemas independently keeps empty schemas visible even when there are no relations to discover.

type Column

type Column struct {
	Name             string   `json:"name"`
	DataType         string   `json:"dataType,omitempty"`
	Ordinal          int      `json:"ordinal,omitempty"`
	Nullable         *bool    `json:"nullable,omitempty"`
	Default          *string  `json:"default,omitempty"`
	Identity         bool     `json:"identity,omitempty"`
	PrimaryKey       bool     `json:"primaryKey,omitempty"`
	Unique           bool     `json:"unique,omitempty"`
	MaxLength        *int     `json:"maxLength,omitempty"`
	NumericPrecision *int     `json:"numericPrecision,omitempty"`
	NumericScale     *int     `json:"numericScale,omitempty"`
	Comment          *string  `json:"comment,omitempty"`
	EnumValues       []string `json:"enumValues,omitempty"`
}

type ForeignKey

type ForeignKey struct {
	Name              string   `json:"name"`
	Columns           []string `json:"columns"`
	ReferencedSchema  string   `json:"referencedSchema,omitempty"`
	ReferencedTable   string   `json:"referencedTable"`
	ReferencedColumns []string `json:"referencedColumns"`
}

type Index

type Index struct {
	Name    string   `json:"name"`
	Unique  bool     `json:"unique,omitempty"`
	Primary bool     `json:"primary,omitempty"`
	Columns []string `json:"columns"`
	Type    string   `json:"type,omitempty"`
	Filter  string   `json:"filter,omitempty"`
}

type Limits

type Limits struct {
	MaxRelations       int
	MaxColumns         int
	MaxMetadata        int
	MaxRoutines        int
	MaxDefinitionBytes int
}

func (Limits) WithDefaults

func (l Limits) WithDefaults() Limits

WithDefaults resolves zero catalog limits to the documented bounds.

type Relation

type Relation struct {
	Name        string       `json:"name"`
	Type        string       `json:"type"`
	ViewDef     string       `json:"viewDefinition,omitempty"`
	Columns     []Column     `json:"columns"`
	Indexes     []Index      `json:"indexes,omitempty"`
	ForeignKeys []ForeignKey `json:"foreignKeys,omitempty"`
	Triggers    []Trigger    `json:"triggers,omitempty"`
}

type Routine

type Routine struct {
	ID         string             `json:"id"`
	Name       string             `json:"name"`
	Type       string             `json:"type"`
	SQL        string             `json:"sql,omitempty"`
	ReturnType string             `json:"returnType,omitempty"`
	Parameters []RoutineParameter `json:"parameters,omitempty"`
}

type RoutineParameter

type RoutineParameter struct {
	Name     string `json:"name"`
	DataType string `json:"dataType,omitempty"`
	Ordinal  int    `json:"ordinal,omitempty"`
}

type Schema

type Schema struct {
	Name      string     `json:"name"`
	Relations []Relation `json:"relations"`
	Routines  []Routine  `json:"routines,omitempty"`
}

type Trigger

type Trigger struct {
	Name     string `json:"name"`
	Event    string `json:"event,omitempty"`
	Timing   string `json:"timing,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
	SQL      string `json:"sql,omitempty"`
}

Directories

Path Synopsis
catalog
sqlserver
Package mssqlcatalog reads SQL Server catalog views into plain row structs.
Package mssqlcatalog reads SQL Server catalog views into plain row structs.
Package snapshot inspects complete SQL Server schemas for migration planning.
Package snapshot inspects complete SQL Server schemas for migration planning.

Jump to

Keyboard shortcuts

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