Documentation
¶
Index ¶
- type Bounds
- type Column
- type ForeignKey
- type Index
- type Inspector
- type PostgresInspector
- func (i *PostgresInspector) GetColumns(ctx context.Context, schema string) ([]*Column, error)
- func (i *PostgresInspector) GetDatabaseName(ctx context.Context) (string, error)
- func (i *PostgresInspector) GetDefaultSchema(ctx context.Context) (string, error)
- func (i *PostgresInspector) GetForeignKeys(ctx context.Context, schema string) ([]*ForeignKey, error)
- func (i *PostgresInspector) GetIndexes(ctx context.Context, schema string) ([]*Index, error)
- func (i *PostgresInspector) GetProcParams(ctx context.Context, schema string) ([]*ProcParam, error)
- func (i *PostgresInspector) GetSchemas(ctx context.Context) ([]string, error)
- func (i *PostgresInspector) GetStoredProcs(ctx context.Context, schema string) ([]*StoredProc, error)
- func (i *PostgresInspector) GetTables(ctx context.Context, schema string, tableType string) ([]*Table, error)
- func (i *PostgresInspector) GetTriggers(ctx context.Context, schema string) ([]*Trigger, error)
- type ProcParam
- type SQLServerInspector
- func (i *SQLServerInspector) GetColumns(ctx context.Context, schema string) ([]*Column, error)
- func (i *SQLServerInspector) GetDatabaseName(ctx context.Context) (string, error)
- func (i *SQLServerInspector) GetDefaultSchema(ctx context.Context) (string, error)
- func (i *SQLServerInspector) GetForeignKeys(ctx context.Context, schema string) ([]*ForeignKey, error)
- func (i *SQLServerInspector) GetIndexes(ctx context.Context, schema string) ([]*Index, error)
- func (i *SQLServerInspector) GetProcParams(ctx context.Context, schema string) ([]*ProcParam, error)
- func (i *SQLServerInspector) GetSchemas(ctx context.Context) ([]string, error)
- func (i *SQLServerInspector) GetStoredProcs(ctx context.Context, schema string) ([]*StoredProc, error)
- func (i *SQLServerInspector) GetTables(ctx context.Context, schema string, tableType string) ([]*Table, error)
- func (i *SQLServerInspector) GetTriggers(ctx context.Context, schema string) ([]*Trigger, error)
- type StoredProc
- type Table
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
Bounds is owned by one inspection. Rows caps each query; DefinitionBytes is consumed across queries and schemas. Oversized definitions are omitted rather than exposing incomplete SQL as a usable object definition.
type Column ¶
type Column struct {
TableName string
ColumnName string
DataType string
IsNullable bool
DefaultValue *string
Position int
IsAutoIncrement bool
IsPrimaryKey bool
IsUnique bool
MaxLength *int // For varchar, char
NumericScale *int // For decimal, numeric
NumericPrecision *int // For decimal, numeric
Comment *string
EnumValues []string // For enum types
}
Column represents a table column
type ForeignKey ¶
type ForeignKey struct {
TableName string
ColumnName string
RefSchemaName string
RefTableName string
RefColumnName string
ConstraintName string
}
ForeignKey represents a foreign key constraint
type Index ¶
type Index struct {
TableName string
IndexName string
IsUnique bool
IsPrimary bool
Columns []string // Ordered list of column names
Type string // btree, hash, gin, gist, etc.
Condition string // WHERE clause for partial indexes
}
Index represents a table index
type Inspector ¶
type Inspector interface {
// Schema operations
GetSchemas(ctx context.Context) ([]string, error)
GetDefaultSchema(ctx context.Context) (string, error)
GetDatabaseName(ctx context.Context) (string, error)
// Table operations
GetTables(ctx context.Context, schema string, tableType string) ([]*Table, error)
GetColumns(ctx context.Context, schema string) ([]*Column, error)
GetIndexes(ctx context.Context, schema string) ([]*Index, error)
GetForeignKeys(ctx context.Context, schema string) ([]*ForeignKey, error)
// Stored procedure operations
GetStoredProcs(ctx context.Context, schema string) ([]*StoredProc, error)
GetProcParams(ctx context.Context, schema string) ([]*ProcParam, error)
// Trigger operations. Dialects without trigger support return (nil, nil);
// only absence-of-feature is signalled by the nil slice, errors are real
// introspection failures.
GetTriggers(ctx context.Context, schema string) ([]*Trigger, error)
}
Inspector provides database introspection capabilities.
Every catalogue method is schema-scoped: it returns a bounded set of rows in one round trip, and each row carries the name of the object that owns it (Column.TableName, Index.TableName, ForeignKey.TableName, ProcParam.ProcName). Callers group; dialects do not. Asking per object turned a schema dump into thousands of round trips for no extra information.
Ordering is part of the contract, not an accident: every method returns rows ordered by owner and then by the object's own natural order (ordinal position, index name, constraint column position, parameter id). Consumers cache and compare catalogs, so row ordering must be deterministic.
type PostgresInspector ¶
type PostgresInspector struct {
// contains filtered or unexported fields
}
PostgresInspector provides PostgreSQL database introspection
func (*PostgresInspector) GetColumns ¶
GetColumns returns every column of every table and view in the schema
func (*PostgresInspector) GetDatabaseName ¶
func (i *PostgresInspector) GetDatabaseName(ctx context.Context) (string, error)
GetDatabaseName returns the current database name
func (*PostgresInspector) GetDefaultSchema ¶
func (i *PostgresInspector) GetDefaultSchema(ctx context.Context) (string, error)
GetDefaultSchema returns the default schema for the current user
func (*PostgresInspector) GetForeignKeys ¶
func (i *PostgresInspector) GetForeignKeys(ctx context.Context, schema string) ([]*ForeignKey, error)
GetForeignKeys returns every foreign key column in the schema.
func (*PostgresInspector) GetIndexes ¶
GetIndexes returns every index on every relation in the schema.
func (*PostgresInspector) GetProcParams ¶
GetProcParams returns the parameters of every routine in the schema.
func (*PostgresInspector) GetSchemas ¶
func (i *PostgresInspector) GetSchemas(ctx context.Context) ([]string, error)
GetSchemas returns all non-system schemas in the database
func (*PostgresInspector) GetStoredProcs ¶
func (i *PostgresInspector) GetStoredProcs(ctx context.Context, schema string) ([]*StoredProc, error)
GetStoredProcs returns all stored procedures and functions in the specified schema
func (*PostgresInspector) GetTables ¶
func (i *PostgresInspector) GetTables(ctx context.Context, schema string, tableType string) ([]*Table, error)
GetTables returns all tables or views in the specified schema
func (*PostgresInspector) GetTriggers ¶
GetTriggers returns triggers in the schema. Not yet implemented for Postgres — returns nil, nil so the extractor can degrade gracefully. TODO: triggers — MSSQL-only for now.
type ProcParam ¶
type ProcParam struct {
ProcID string
ProcName string
ParamName string
DataType string
Position int
}
ProcParam represents a stored procedure parameter
type SQLServerInspector ¶
type SQLServerInspector struct {
// contains filtered or unexported fields
}
SQLServerInspector provides SQL Server database introspection. Catalog SQL is owned by internal/mssqlcatalog; this type maps its rows onto the inspector models and applies the inspection's row and definition bounds.
func (*SQLServerInspector) GetColumns ¶
GetColumns returns every column of every table and view in the schema.
Widths, precision and scale are the INFORMATION_SCHEMA character values, not sys.columns byte sizes: the browser needs character widths.
func (*SQLServerInspector) GetDatabaseName ¶
func (i *SQLServerInspector) GetDatabaseName(ctx context.Context) (string, error)
GetDatabaseName returns the current database name
func (*SQLServerInspector) GetDefaultSchema ¶
func (i *SQLServerInspector) GetDefaultSchema(ctx context.Context) (string, error)
GetDefaultSchema returns the default schema for the current user
func (*SQLServerInspector) GetForeignKeys ¶
func (i *SQLServerInspector) GetForeignKeys(ctx context.Context, schema string) ([]*ForeignKey, error)
GetForeignKeys returns every foreign key column in the schema, one row per participating column, in constraint column order.
func (*SQLServerInspector) GetIndexes ¶
GetIndexes returns every named index on every table in the schema. Columns is the ordered key; included columns are excluded.
func (*SQLServerInspector) GetProcParams ¶
func (i *SQLServerInspector) GetProcParams(ctx context.Context, schema string) ([]*ProcParam, error)
GetProcParams returns the parameters of every stored procedure and function in the schema. A scalar function's return value (parameter_id 0) is not a parameter; GetStoredProcs reports it as ReturnType.
func (*SQLServerInspector) GetSchemas ¶
func (i *SQLServerInspector) GetSchemas(ctx context.Context) ([]string, error)
GetSchemas returns all non-system schemas in the database
func (*SQLServerInspector) GetStoredProcs ¶
func (i *SQLServerInspector) GetStoredProcs(ctx context.Context, schema string) ([]*StoredProc, error)
GetStoredProcs returns all stored procedures and functions in the specified schema
func (*SQLServerInspector) GetTables ¶
func (i *SQLServerInspector) GetTables(ctx context.Context, schema string, tableType string) ([]*Table, error)
GetTables returns all tables or views in the specified schema
func (*SQLServerInspector) GetTriggers ¶
GetTriggers returns all DML triggers in the given schema, grouped by (schema, name). A single trigger firing on multiple events (e.g. INSERT+UPDATE) is returned as one row with a comma-joined Event string.
type StoredProc ¶
type StoredProc struct {
ID string
Schema string
Name string
Type string // "procedure" or "function"
SQL string // Complete SQL body/definition
ReturnType string // For functions: the SQL return type (e.g. "int", "TABLE"); empty for procedures
}
StoredProc represents a stored procedure or function
type Table ¶
type Table struct {
Schema string
Name string
Type string // "table" or "view"
ViewDef string // SQL definition for views
}
Table represents a database table or view
type Trigger ¶
type Trigger struct {
Schema string
Name string
TableName string
Event string
Timing string
IsDisabled bool
SQL string // CREATE TRIGGER body from OBJECT_DEFINITION
}
Trigger represents a database trigger attached to a table.
Event is one or more trigger events, comma-joined when a single trigger fires on multiple DML actions (e.g. "INSERT,UPDATE"). Timing is "AFTER" or "INSTEAD OF" for SQL Server, which does not support BEFORE triggers.