sqlserver

package
v4.17.0-clickv2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 13 Imported by: 0

README

Microsoft SQL Server

sqlserver://username:password@host/instance?param1=value&param2=value sqlserver://username:password@host:port?param1=value&param2=value

URL Query WithInstance Config Description
x-migrations-table MigrationsTable Name of the migrations table
username enter the SQL Server Authentication user id or the Windows Authentication user id in the DOMAIN\User format. On Windows, if user id is empty or missing Single-Sign-On is used.
password The user's password.
host The host to connect to.
port The port to connect to.
instance SQL Server instance name.
database DatabaseName The name of the database to connect to
connection+timeout in seconds (default is 0 for no timeout), set to 0 for no timeout.
dial+timeout in seconds (default is 15), set to 0 for no timeout.
encrypt disable - Data send between client and server is not encrypted. false - Data sent between client and server is not encrypted beyond the login packet (Default). true - Data sent between client and server is encrypted.
app+name The application name (default is go-mssqldb).
useMsi true - Use Azure MSI Authentication for connecting to Sql Server. Must be running from an Azure VM/an instance with MSI enabled. false - Use password authentication (Default). See here for Azure MSI Auth details. NOTE: Since this cannot be tested locally, this is not officially supported.

See https://github.com/microsoft/go-mssqldb for full parameter list.

Driver Support

Which go-mssqldb driver to us?

Please note that the deprecated mssql driver is not supported. Please use the newer sqlserver driver.
See https://github.com/microsoft/go-mssqldb#deprecated for more information.

Official Support by migrate

Versions of MS SQL Server 2019 newer than CTP3.1 are not officially supported since there are issues testing against the Docker image. For more info, see: https://github.com/golang-migrate/migrate/issues/160#issuecomment-522433269

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilConfig                 = fmt.Errorf("no config")
	ErrNoDatabaseName            = fmt.Errorf("no database name")
	ErrNoSchema                  = fmt.Errorf("no schema")
	ErrDatabaseDirty             = fmt.Errorf("database is dirty")
	ErrMultipleAuthOptionsPassed = fmt.Errorf("both password and useMsi=true were passed.")
)
View Source
var DefaultMigrationsTable = "schema_migrations"

DefaultMigrationsTable is the name of the migrations table in the database

Functions

func WithInstance

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error)

WithInstance returns a database instance from an already created database connection.

Note that the deprecated `mssql` driver is not supported. Please use the newer `sqlserver` driver.

Types

type Config

type Config struct {
	MigrationsTable string
	DatabaseName    string
	SchemaName      string
}

Config for database

type SQLServer

type SQLServer struct {
	// contains filtered or unexported fields
}

SQL Server connection

func (*SQLServer) Close

func (ss *SQLServer) Close() error

Close the database connection

func (*SQLServer) Drop

func (ss *SQLServer) Drop() error

Drop all tables from the database.

func (*SQLServer) Lock

func (ss *SQLServer) Lock() error

Lock creates an advisory local on the database to prevent multiple migrations from running at the same time.

func (*SQLServer) Open

func (ss *SQLServer) Open(url string) (database.Driver, error)

Open a connection to the database.

func (*SQLServer) Run

func (ss *SQLServer) Run(migration io.Reader) error

Run the migrations for the database

func (*SQLServer) SetVersion

func (ss *SQLServer) SetVersion(version int, dirty bool) error

SetVersion for the current database

func (*SQLServer) Unlock

func (ss *SQLServer) Unlock() error

Unlock froms the migration lock from the database

func (*SQLServer) Version

func (ss *SQLServer) Version() (version int, dirty bool, err error)

Version of the current database state

Jump to

Keyboard shortcuts

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