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

azuresql

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 20 Imported by: 0

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 11
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.
  • Engine data does not survive a restore: containers start empty and tracked databases are created again.
  • 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.
  • Entra authentication, firewall rules, TLS and public-network settings, and pool or sku limits are stored but not enforced.
  • Engine data does not survive a snapshot restore.
  • No dashboard page.

More

Documentation

Index

Constants

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")
)

Functions

This section is empty.

Types

type ConfigProvider

type ConfigProvider interface {
	GetAzureSQLSettings() Settings
}

ConfigProvider extracts the Azure SQL settings from the AppContext config.

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) 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) 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. Engine data is not persisted: containers start empty on restore and the tracked databases are created again.

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