sqlserver

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Dialect = "tsql"

Dialect is the sqlglot dialect the driver parses T-SQL with.

Variables

View Source
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{}}

DefaultDiff provides basic diffing capabilities for SQL Server. A Driver opened on a connection exposes the same Differ.

View Source
var DefaultPlan = Planner{}

DefaultPlan generates SQL Server migration statements without a database connection.

Functions

func CatalogType

func CatalogType(c CatalogColumn) (schema.Type, error)

func CollationChanged added in v1.1.0

func CollationChanged(from, to *schema.Column) bool

CollationChanged reports an explicit collation change between two columns.

func CreateOrAlter

func CreateOrAlter(definition string) (string, error)

CreateOrAlter rewrites a CREATE PROCEDURE|FUNCTION definition to CREATE OR ALTER, splicing the two words in after the CREATE keyword so every other byte of the definition -- comments, layout, literals -- is kept.

func DefaultSQL added in v1.0.5

func DefaultSQL(c *schema.Column) (string, error)

DefaultSQL is the SQL text of a column default. An HCL string literal arrives unquoted and is quoted for the column's type, N'...' for the Unicode types; numbers and raw sql() expressions are written as they are.

func FormatType

func FormatType(t schema.Type) (string, error)

FormatType writes a schema.Type in its canonical T-SQL spelling, so two spellings of one type format the same.

func IndexDefinitionChanged added in v1.1.0

func IndexDefinitionChanged(from, to []schema.Attr) bool

IndexDefinitionChanged reports index attribute changes other than fill factor, which a rebuild applies in place.

func ParseType

func ParseType(s string) (schema.Type, error)

ParseType reads a declared T-SQL data type (`nvarchar(max)`, `decimal(18,2)`) through sqlglot into its schema.Type.

func QualifyDefinition added in v1.1.0

func QualifyDefinition(definition, schema string) (string, error)

QualifyDefinition prefixes an unqualified module name -- and a trigger's unqualified ON target -- with schema. SQL Server creates an unqualified module in the executing login's default schema, so a replayed definition must name the schema the catalog placed it in. Every other byte is kept.

func RowGUIDChanged added in v1.1.0

func RowGUIDChanged(from, to *schema.Column) bool

RowGUIDChanged reports a ROWGUIDCOL property change between two columns.

Types

type CatalogColumn

type CatalogColumn struct {
	Name      string
	DataType  string
	MaxLength *int
	Precision *int
	Scale     *int
}

CatalogType maps a catalog column to its schema.Type from the raw sys.columns widths: bytes for string and binary types (halved for the n-types), -1 for (max), precision and scale for decimals and floats, and the fractional-second digits as the scale of time types.

type Clustered

type Clustered struct {
	schema.Attr
}

Clustered marks a clustered index or primary key. Its absence means nonclustered.

type DefaultConstraint

type DefaultConstraint struct {
	schema.Attr
	Name string
	// SystemNamed marks a name SQL Server generated; it is not compared,
	// and a new default for it is created unnamed.
	SystemNamed bool
}

DefaultConstraint names the constraint holding a column default. The inspector sets it from the catalog; the planner names new defaults DF_<table>_<column>.

type Definition

type Definition struct {
	schema.Attr
	Text string
	// Unparsed marks a definition known by its header alone, which is compared
	// as written. Comparing any other that is not read whole is an error.
	Unparsed bool
}

Definition is the T-SQL text a routine is created from: the declared .sql batch for a desired routine, sys.sql_modules.definition for a live one. The differ compares definitions by their sqlglot canonical form, and the planner executes a declared definition as written.

type Disabled

type Disabled struct {
	schema.Attr
}

type FillFactor added in v1.1.0

type FillFactor struct {
	schema.Attr
	Percent int
}

FillFactor is an index's FILLFACTOR percentage, 1-99. Its absence is the server default (0, equivalent to 100).

type Header struct {
	// Kind is PROCEDURE, FUNCTION, VIEW or TRIGGER.
	Kind, Schema, Name string
}

Header is the kind and name a CREATE [OR ALTER] module definition declares. Schema is empty when the name is unqualified.

func HeaderOf added in v1.3.2

func HeaderOf(definition string) (Header, error)

HeaderOf reads a module's header from its tokens, without reading its body.

type Identity

type Identity struct {
	schema.Attr
	Seed, Increment int64
}

Identity is an IDENTITY(seed, increment) column.

type IndexInclude

type IndexInclude struct {
	schema.Attr
	Columns []string
}

IndexInclude lists the non-key columns an index INCLUDEs.

type IndexPredicate

type IndexPredicate struct {
	schema.Attr
	P string
	// contains filtered or unexported fields
}

IndexPredicate is a filtered index's WHERE clause.

type Partial added in v1.3.8

type Partial struct {
	schema.Attr
}

Partial marks a declared table that names only some of its members (`partial = true`). The differ never compares it.

type Phase added in v1.3.8

type Phase int

Phase says where a statement belongs when a caller orders statements across changes: every drop, then every alter, then every create.

const (
	PhaseDrop Phase = iota
	PhaseAlter
	PhaseCreate
)

type PhasedChange added in v1.3.8

type PhasedChange struct {
	*migrate.Change
	Phase Phase
}

PhasedChange is one planned statement and its phase.

type Planner

type Planner struct{}

Planner generates SQL for schema changes without a database connection.

func (Planner) PlanChanges

func (Planner) PlanChanges(_ context.Context, name string, changes []schema.Change, opts ...migrate.PlanOption) (*migrate.Plan, error)

PlanChanges returns a migration plan for the given schema changes. Each statement is its own change, so a routine definition runs as its own batch. The statements stay valid at compatibility level 100.

func (Planner) PlanPhased added in v1.3.8

func (Planner) PlanPhased(_ context.Context, name string, changes []schema.Change, opts ...migrate.PlanOption) ([]PhasedChange, error)

PlanPhased is PlanChanges with each statement's phase.

type QuotedIdentifierOff added in v1.1.0

type QuotedIdentifierOff struct {
	schema.Attr
}

QuotedIdentifierOff marks a module created under SET QUOTED_IDENTIFIER OFF.

type Routine

type Routine struct {
	// Kind is PROCEDURE or FUNCTION.
	Kind string
	// Schema is the schema the definition names, empty when unqualified.
	Schema string
	Name   string
	// Text is the definition as written.
	Text string
	// contains filtered or unexported fields
}

Routine is one CREATE PROCEDURE or CREATE FUNCTION read from its definition.

func ParseRoutine

func ParseRoutine(definition string) (*Routine, error)

ParseRoutine parses a single CREATE [OR ALTER] PROCEDURE|FUNCTION batch. A batch holding anything else, or more than one statement, is an error; one that is not read whole is an UnparsedError.

func UnparsedRoutine added in v1.3.2

func UnparsedRoutine(definition string) (*Routine, error)

UnparsedRoutine is the routine definition declares, known by its header alone: it has no arguments or return type, and is created as written.

func (*Routine) AddTo

func (r *Routine) AddTo(s *schema.Schema) error

AddTo adds the routine to s as a schema.Proc or schema.Func carrying its Definition. A routine qualified with another schema is an error.

type RowGUID added in v1.1.0

type RowGUID struct {
	schema.Attr
}

RowGUID marks the table's ROWGUIDCOL column.

type Sequence added in v1.1.0

type Sequence struct {
	schema.Object
	Schema                                *schema.Schema
	Name, Type, Start, Increment, Minimum string
	Maximum                               string
	Cycle, NoCache                        bool
	CacheSize                             int64
}

Sequence is a CREATE SEQUENCE schema object. Bounds are exact decimal strings; CacheSize 0 with NoCache false is the server default cache.

type SpecialType

type SpecialType struct {
	schema.Type
	T string
}

SpecialType is a SQL Server type with no generic Atlas counterpart: money, smallmoney, xml, sql_variant and rowversion.

type TableType added in v1.1.0

type TableType struct {
	schema.Object
	Schema  *schema.Schema
	Name    string
	Columns []*schema.Column
	Keys    []*schema.Index
	Checks  []string
}

TableType is a CREATE TYPE ... AS TABLE schema object. Its defaults, keys and checks are unnamed: SQL Server names a table type's constraints itself.

func FindTableType added in v1.1.0

func FindTableType(s *schema.Schema, qualified string) *TableType

FindTableType resolves a [schema.]name parameter type to a table type declared in s, matching names case-insensitively as the catalog does.

type TableTypePrimaryKey added in v1.1.0

type TableTypePrimaryKey struct {
	schema.Attr
}

TableTypePrimaryKey marks the key of a table type that is its PRIMARY KEY; the others are UNIQUE.

type TableTypeRef added in v1.1.0

type TableTypeRef struct {
	schema.Type
	T *TableType
}

TableTypeRef is a routine parameter typed by a user-defined table type.

type UniqueConstraint

type UniqueConstraint struct {
	schema.Attr
}

UniqueConstraint marks a live unique index that backs a UNIQUE constraint, which is dropped with ALTER TABLE ... DROP CONSTRAINT.

type UnparsedError added in v1.3.2

type UnparsedError struct {
	Diagnostics []sqlglot.ParseDiagnostic
}

UnparsedError is a definition sqlglot does not read whole, so nothing but its header is known. SQL Server may still accept it.

func (*UnparsedError) Error added in v1.3.2

func (e *UnparsedError) Error() string

Jump to

Keyboard shortcuts

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