mssql

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 13 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 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
}

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.

For Azure SQL Database, Azure AD authentication (options 1-2) is recommended. For on-premises SQL Server, use SQL Server Authentication (option 3).

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