mssql

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPermissionError added in v0.15.3

func IsPermissionError(err error) bool

IsPermissionError reports whether err indicates the DWH credentials lack the privileges required for the attempted operation.

func IsUnavailableError added in v0.21.0

func IsUnavailableError(err error) bool

IsUnavailableError reports whether err says the server has no such object, column or function: a catalog view or column this version or edition (Azure SQL Edge, Azure SQL Database, Fabric) lacks. No grant fixes it, unlike a permission error, and retrying does not either.

func NewQuerier

func NewQuerier[T any](conn *MSSQLExecutor) querier.Querier[T]

Types

type MSSQLConf

type MSSQLConf struct {
	// User is the SQL Server login or Azure AD username.
	// For Azure AD Service Principal, this is the Application (Client) ID.
	// Leave empty when using AccessToken or Azure AD Managed Identity.
	User string
	// Password is the SQL Server login password or Azure AD client secret.
	Password string
	// Host is the hostname or IP address.
	// For Azure SQL: e.g. "yourserver.database.windows.net"
	Host string
	// Port is the SQL Server port. Default: 1433.
	Port int
	// Database is the database name to connect to.
	// SQL Server is database-scoped — create a separate connection per database.
	Database string

	// TrustCert skips TLS server certificate verification.
	// Not recommended for production Azure SQL connections.
	TrustCert bool
	// Encrypt controls connection encryption.
	// Values: "true" (default, required for Azure SQL), "false", "disable".
	Encrypt string

	// FedAuth specifies the Azure AD federated authentication method.
	// When set, the azuread driver is used instead of the standard sqlserver driver.
	// Common values for cloud deployments:
	//   - "ActiveDirectoryDefault": chained credential (Managed Identity → environment → CLI)
	//   - "ActiveDirectoryMSI": Azure Managed Identity (system or user-assigned)
	//   - "ActiveDirectoryServicePrincipal": app registration with client ID + secret
	//   - "ActiveDirectoryAzCli": reuse Azure CLI authentication
	// See https://pkg.go.dev/github.com/microsoft/go-mssqldb/azuread for all options.
	FedAuth string

	// AccessToken is a pre-acquired Azure AD OAuth access token.
	// When set, it takes precedence over all other authentication methods.
	// The token is passed directly to the driver via NewAccessTokenConnector.
	AccessToken string

	// ApplicationClientID is the Azure AD Application (Client) ID.
	// Used with ActiveDirectoryServicePrincipal (identifies the app registration)
	// and ActiveDirectoryMSI with user-assigned managed identity (resource ID).
	ApplicationClientID string

	// IntegratedAuth signs in as the identity running the process, the same as `sqlcmd -E`:
	// the logged-in Windows user (SSPI) on Windows, and the Kerberos ticket from `kinit` elsewhere.
	// User, Password, AccessToken and FedAuth must be empty.
	IntegratedAuth bool
}

MSSQLConf configures a connection to Microsoft SQL Server or Azure SQL Database.

Authentication methods (in order of priority):

  1. Access Token: set AccessToken to a pre-acquired Azure AD OAuth token.
  2. Azure AD Federated Auth: set FedAuth to an Azure AD method (e.g. ActiveDirectoryDefault, ActiveDirectoryMSI, ActiveDirectoryServicePrincipal). Used with Azure SQL Database.
  3. SQL Server Authentication: set User and Password for standard username/password auth.
  4. Integrated Authentication: set IntegratedAuth to sign in as the identity running the process.

For Azure SQL Database, Azure AD authentication (options 1-2) is recommended. For on-premises SQL Server, use SQL Server Authentication (option 3) or, where the server accepts Windows Authentication, Integrated Authentication (option 4).

type MSSQLExecutor

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

func NewMSSQLExecutor

func NewMSSQLExecutor(ctx context.Context, conf *MSSQLConf) (*MSSQLExecutor, error)

func (*MSSQLExecutor) Close

func (e *MSSQLExecutor) Close() error

func (*MSSQLExecutor) Exec

func (e *MSSQLExecutor) Exec(ctx context.Context, query string, args ...any) error

func (*MSSQLExecutor) GetDb

func (e *MSSQLExecutor) GetDb() *sqlx.DB

func (*MSSQLExecutor) QueryRows

func (e *MSSQLExecutor) QueryRows(ctx context.Context, sql string, args ...interface{}) (*sqlx.Rows, error)

func (*MSSQLExecutor) Select added in v0.11.0

func (e *MSSQLExecutor) Select(ctx context.Context, dest any, query string, args ...any) error

Jump to

Keyboard shortcuts

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