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

sqlserver

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: 12 Imported by: 0

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 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.6

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 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.

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
}

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
}

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 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 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.

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.

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 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 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.

Jump to

Keyboard shortcuts

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