azuresql

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 22 Imported by: ? 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.

README

Azure SQL Database

Parity grade: B · SDK azure-sdk-for-go/sdk/resourcemanager/sql/armsql@v1.2.0 · last audited 2026-10-22 (4939f3c07)

Coverage

Metric Value
PARITY entries audited 14 (10 ok, 4 partial)
Feature families 3 (3 ok)
Known gaps 8
Deferred items 0
Resource leaks clean
Known gaps
  • Azure SQL managed instances, SQL pools, replicas, failover groups, geo-replication, restore, copy and long-term retention data flow are not implemented; createMode other than Default is rejected.
  • Entra authentication, firewall rules, minimalTlsVersion, publicNetworkAccess, elastic-pool limits and database sku/edition limits are stored but not enforced by the engine.
  • Database sku and maxSizeBytes do not size the engine; every database is a plain SQL Server database.
  • Server create waits for the container, so a first run that pulls the image can take minutes; ARM operations are reported complete as soon as the request returns.
  • Server-level administrator login is a sysadmin of its container, not Azure's dbmanager and loginmanager roles.
  • The restorableDroppedDatabases collection is always empty.
  • Managed instances, failover groups, geo-replication, restore, copy and long-term retention data flow are not implemented: the Microsoft.Sql resource model and createMode handling live in services/azurearm (rp_sql*.go), outside this service, and the engine seam has no cross-server data transfer.
  • Entra authentication, firewall rules, TLS and public-network settings, and pool or sku limits are stored but not enforced: the rules and settings are ARM child state in services/azurearm, and enforcing them needs a connection relay in front of the TDS port that the azurearm.SQL seam does not feed.

More

Documentation

Index

Constants

View Source
const (
	MaxQueryLen   = 4000
	MaxQueryRows  = 500
	MaxCellLen    = 1000
	QueryDeadline = 20 * time.Second
)

Query limits.

View Source
const (
	// EngineAuto launches SQL Server containers when a container runtime is reachable.
	EngineAuto = "auto"
	// EngineNone never starts containers: servers are state-only.
	EngineNone = "none"
	// DefaultImage is the SQL Server image servers run.
	DefaultImage = "mcr.microsoft.com/mssql/server:2022-CU26-ubuntu-22.04"
	// DefaultStartupTimeout bounds how long a server container may take to accept connections.
	DefaultStartupTimeout = 5 * time.Minute
)

Variables

View Source
var (
	// ErrNotFound is returned for an unknown server.
	ErrNotFound = errors.New("azuresql: server not found")
	// ErrInvalid is returned for a malformed request.
	ErrInvalid = errors.New("azuresql: invalid request")
	// ErrRuntimeUnavailable is returned by a Launcher when no container runtime is reachable; the server then
	// runs state-only.
	ErrRuntimeUnavailable = errors.New("azuresql: container runtime unavailable")
	// ErrNilAppContext is returned when Init is called with a nil AppContext.
	ErrNilAppContext = errors.New("azuresql: nil app context")
)
View Source
var ErrNoEngine = fmt.Errorf("%w: server has no SQL engine (state-only)", ErrInvalid)

ErrNoEngine is returned when the server has no SQL engine (no container runtime) to run a query.

Functions

func ValidateDatabaseName

func ValidateDatabaseName(name string) error

ValidateDatabaseName accepts a plain database name.

func ValidateQuery

func ValidateQuery(text string) error

ValidateQuery accepts one plain SELECT statement: no comments, no batch separators and none of the keywords that write, execute or reach outside the database.

Types

type ConfigProvider

type ConfigProvider interface {
	GetAzureSQLSettings() Settings
}

ConfigProvider extracts the Azure SQL settings from the AppContext config.

type DataEngine

type DataEngine interface {
	Engine
	// BackupDatabase returns a backup of the database; it fails when the backup would exceed maxBytes.
	BackupDatabase(ctx context.Context, name string, maxBytes int64) ([]byte, error)
	// RestoreDatabase replaces the database with the content of a backup taken by BackupDatabase.
	RestoreDatabase(ctx context.Context, name string, data []byte) error
}

DataEngine is an Engine that can export and import the content of a database, so snapshots keep engine data.

type Database

type Database struct {
	Name      string `json:"name"`
	Collation string `json:"collation,omitempty"`
}

Database is a database the backend has created on a server.

type Endpoint

type Endpoint struct {
	Host string
	Port int
}

Endpoint is where a server's TDS port listens. Port is 0 when the server is state-only.

type Engine

type Engine interface {
	// Endpoint is the host and published TDS port clients connect to.
	Endpoint() (string, int)
	// SetLogin creates the server-admin login, or resets its password, with sysadmin rights.
	SetLogin(ctx context.Context, login, password string) error
	CreateDatabase(ctx context.Context, name, collation string) error
	DropDatabase(ctx context.Context, name string) error
	ListDatabases(ctx context.Context) ([]string, error)
	Close(ctx context.Context)
}

Engine is one running SQL Server. Methods are safe for sequential use per server.

type Handler

type Handler struct {
	Backend *InMemoryBackend
	// contains filtered or unexported fields
}

Handler owns the SQL servers. Azure SQL has no HTTP data plane: ARM manages servers and clients speak TDS to each server's own port, so the handler never matches a request.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler wraps backend.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the operations ARM's Microsoft.Sql provider drives.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset stops every server.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches.

func (*Handler) Shutdown

func (h *Handler) Shutdown(context.Context)

Shutdown stops every server and releases the runtime client.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable.

type InMemoryBackend

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

InMemoryBackend runs one SQL Server container per logical server, or tracks the server state-only when no container runtime is reachable. mu guards the map; life serialises lifecycle calls so a slow container start does not block reads.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend with no launcher: servers are state-only.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close stops every server.

func (*InMemoryBackend) Databases

func (b *InMemoryBackend) Databases(id string) ([]string, error)

Databases lists the user databases the engine holds, or the tracked ones when the server is state-only.

func (*InMemoryBackend) Delete

func (b *InMemoryBackend) Delete(id string) error

Delete stops the server and releases its port; a missing server is ErrNotFound.

func (*InMemoryBackend) DropDatabase

func (b *InMemoryBackend) DropDatabase(id, name string) error

DropDatabase drops the database from the engine; a missing database is not an error.

func (*InMemoryBackend) Endpoint

func (b *InMemoryBackend) Endpoint(id string) (Endpoint, bool)

Endpoint reports where the server's TDS port listens; ok is false for an unknown server.

func (*InMemoryBackend) Ensure

func (b *InMemoryBackend) Ensure(id string, spec Spec) (Endpoint, error)

Ensure creates the server's engine, or applies a changed admin login or password to an existing one.

func (*InMemoryBackend) EnsureDatabase

func (b *InMemoryBackend) EnsureDatabase(id, name, collation string) error

EnsureDatabase creates the database in the engine; an existing database is left as it is.

func (*InMemoryBackend) Query

func (b *InMemoryBackend) Query(ctx context.Context, id, database, text string) (QueryResult, error)

Query runs a validated read-only SELECT on database and returns at most MaxQueryRows rows.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset stops every server.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot, starting every server again on a fresh port.

func (*InMemoryBackend) ServerIDByName

func (b *InMemoryBackend) ServerIDByName(name string) (string, bool)

ServerIDByName returns the id of the server whose resource name is name.

func (*InMemoryBackend) SetLauncher

func (b *InMemoryBackend) SetLauncher(l Launcher, startup time.Duration)

SetLauncher makes new servers start engines through l.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises every server's spec and database list, plus a backup of each database's content when the engine can export one; a database whose backup fails or exceeds the size caps is saved without data.

type LaunchSpec

type LaunchSpec struct {
	ID       string
	Login    string
	Password string
}

LaunchSpec describes the engine of one logical server.

type Launcher

type Launcher interface {
	Launch(ctx context.Context, spec LaunchSpec) (Engine, error)
}

Launcher starts engines.

type Provider

type Provider struct{}

Provider implements service.Provider for Azure SQL Database.

func (*Provider) Init

Init builds the backend and handler.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Querier

type Querier interface {
	Query(ctx context.Context, database, text string, maxRows int) (QueryResult, error)
}

Querier is implemented by engines that run read-only queries.

type QueryResult

type QueryResult struct {
	Columns   []string
	Rows      [][]string
	Truncated bool
}

QueryResult is a capped result set; every cell is text.

type Settings

type Settings struct {
	Engine string `` //nolint:lll // config struct tags are intentionally verbose
	/* 272-byte string literal not displayed */
	Image string `` //nolint:lll // config struct tags are intentionally verbose
	/* 224-byte string literal not displayed */
	StartupTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
	/* 243-byte string literal not displayed */
}

Settings is the Kong-embedded configuration of the Azure SQL Database emulator.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider exists.

type Spec

type Spec struct {
	AdminLogin    string `json:"adminLogin"`
	AdminPassword string `json:"adminPassword"`
}

Spec is the part of a logical server's ARM configuration the engine acts on. An empty AdminLogin (Entra-only server) creates no SQL login; an empty AdminPassword on an existing server keeps the current one.

Jump to

Keyboard shortcuts

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