Documentation
¶
Overview ¶
Package mssqlcatalog reads SQL Server catalog views into plain row structs.
It is the single owner of the catalog SQL shared by the schema inspector and the Atlas SQL Server driver. Every query is schema-scoped, runs in one round trip, pushes name filters into SQL as ordinary binds, and returns rows in a deterministic owner-then-natural order.
Queries must run on databases at compatibility level 100 (OIPA): no STRING_AGG, no OPENJSON. Ordered string aggregation uses FOR XML PATH, and name filters are plain `IN (@p1, @p2, ...)` lists. Each query text starts with its outer SELECT so a caller may prefix it with a TOP bound.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CheckConstraint ¶
type CheckConstraint struct {
Table string
Name string
Definition string
Column *string
Disabled bool
}
CheckConstraint is one CHECK constraint. Column is set only for a column-level constraint.
func CheckConstraints ¶
CheckConstraints lists every check constraint in the scope ordered by table then constraint name.
type Column ¶
type Column struct {
Table string
Name string
DataType string
Nullable bool
Default *string
DefaultConstraint *string
Position int
CharMaxLength *int
NumericPrecision *int
NumericScale *int
MaxLength *int
Precision *int
Scale *int
PrimaryKey bool
Unique bool
Identity bool
IdentitySeed *int64
IdentityIncrement *int64
Computed bool
UserDefinedType bool
}
Column is one table or view column.
CharMaxLength, NumericPrecision and NumericScale come from INFORMATION_SCHEMA (character widths, -1 for max; nil for types without one). MaxLength, Precision and Scale are the raw sys.columns values (bytes, so nvarchar is doubled; -1 for max) that DDL generation needs; they are nil only when the sys.columns join misses. Default is the default expression and DefaultConstraint the name of the constraint holding it. IdentitySeed and IdentityIncrement are set for identity columns. Computed and UserDefinedType flag columns DDL generation cannot reproduce.
type ForeignKey ¶
type ForeignKey struct {
Table string
Name string
Column string
RefSchema string
RefTable string
RefColumn string
OnDelete string
OnUpdate string
}
ForeignKey is one participating column of a foreign key. OnDelete and OnUpdate are the referential action descriptions (NO_ACTION, CASCADE, ...).
func ForeignKeys ¶
ForeignKeys lists every foreign key column in the scope. Rows are ordered by table, constraint, then constraint_column_id; that last key is load-bearing, because callers pair local and referenced columns positionally.
type Index ¶
type Index struct {
Table string
Name string
Unique bool
Primary bool
UniqueConstraint bool
KeyColumns []string
TypeDesc string
Filter string
}
Index is one named index on a table. KeyColumns is the ordered key (included columns excluded); IndexColumns returns the full per-column detail. TypeDesc is sys.indexes.type_desc (CLUSTERED, NONCLUSTERED, ...); Filter is the filtered-index predicate, empty when unfiltered.
func Indexes ¶
Indexes lists every named index on every table in the scope, ordered by table then index name. Views are absent: the join is to sys.tables.
Key columns are aggregated with FOR XML PATH, not STRING_AGG ... WITHIN GROUP, which compatibility levels below 140 reject. The `, TYPE).value(...)` projection keeps XML metacharacters intact and yields nvarchar(max).
type IndexColumn ¶
type IndexColumn struct {
Table string
Index string
Column string
KeyOrdinal int
Included bool
Descending bool
}
IndexColumn is one column of a named index. KeyOrdinal is 0 for included columns.
func IndexColumns ¶
IndexColumns lists the key and included columns of every named index in the scope, ordered by table, index, key columns by key ordinal, then included columns by index column id.
type Parameter ¶
type Parameter struct {
Routine string
Name string
DataType string
Position int
MaxLength int
Precision int
Scale int
Output bool
}
Parameter is one declared routine parameter. A scalar function's return value (parameter_id 0) is excluded; Routine.ReturnType carries it.
type Queryer ¶
type Queryer interface {
QueryContext(ctx context.Context, query string, args ...any) (Rows, error)
}
Queryer runs a catalog query. Callers that bound or instrument queries implement it; FromDB adapts a plain *sql.DB.
type Routine ¶
type Routine struct {
Schema string
Name string
Type RoutineType
Definition *string
ReturnType *string
}
Routine is one stored procedure or T-SQL function. Definition is the sys.sql_modules text (nil when withheld or encrypted). ReturnType is the scalar return type for FN, "TABLE" for IF/TF, and nil for procedures.
type RoutineType ¶
type RoutineType string
RoutineType is the sys.objects type code of a routine.
const ( Procedure RoutineType = "P" ScalarFunction RoutineType = "FN" InlineTableFunction RoutineType = "IF" TableFunction RoutineType = "TF" )
func (RoutineType) IsFunction ¶
func (t RoutineType) IsFunction() bool
IsFunction reports whether t is one of the function types.
type Scope ¶
type Scope struct {
// Schema is the owning schema; required.
Schema string
// Names restricts rows to these owning objects (tables for table-level
// queries, routines for Routines and Parameters). Empty means all.
Names []string
// DefinitionLimit truncates object definitions server-side to this many
// characters. Zero returns definitions in full.
DefinitionLimit int
}
Scope selects the catalog rows a query returns.
type Table ¶
Table is one INFORMATION_SCHEMA.TABLES row. Type is the catalog's TABLE_TYPE ("BASE TABLE" or "VIEW"); Definition is the view body, empty for tables and nil when the catalog withholds it.
type TableFeature ¶
TableFeature is a table property DDL generation does not manage: Feature is "partitioned", or "trigger <name>" for each trigger on the table.
func UnmanagedFeatures ¶
UnmanagedFeatures lists the partitioned tables and table triggers in the scope, ordered by table then feature.