sqldb

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PostgresDialect = Dialect{
					// contains filtered or unexported fields
	}

	CockroachDialect = Dialect{
						// contains filtered or unexported fields
	}

	MySQLDialect = Dialect{
					// contains filtered or unexported fields
	}

	SQLiteDialect = Dialect{
					// contains filtered or unexported fields
	}

	SQLServerDialect = Dialect{
						// contains filtered or unexported fields
	}

	OracleDialect = Dialect{
					// contains filtered or unexported fields
	}

	ClickHouseDialect = Dialect{
						// contains filtered or unexported fields
	}

	DuckDBDialect = Dialect{
					// contains filtered or unexported fields
	}
)

Dialects for common database drivers.

Functions

func IsSupportedDriver

func IsSupportedDriver(driver string) bool

IsSupportedDriver reports whether the driver identifier belongs to a supported SQL engine.

func RewriteNamedQuery

func RewriteNamedQuery(query string, args map[string]any, d Dialect) (string, []any, error)

RewriteNamedQuery converts @name parameter placeholders into dialect placeholders ($1, ?, @p1) and returns the ordered slice of arguments matching the placeholders.

Types

type Config

type Config struct {
	Driver string
	Name   string
	Source string
	Pool   PoolConfig
}

Config represents the declaration of a single relational database connection pool.

func (Config) Key

func (c Config) Key() string

Key returns the short identifier (e.g. "postgres.primary").

func (Config) Reference

func (c Config) Reference() string

Reference returns the full manifest reference path (e.g. "connection.postgres.primary").

type Dialect

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

Dialect provides database-specific placeholder formatting and error code matching.

func ResolveDialect

func ResolveDialect(driver string) Dialect

ResolveDialect returns the canonical Dialect for a given database driver name.

func (Dialect) ExtractErrorCode

func (d Dialect) ExtractErrorCode(err error) string

ExtractErrorCode extracts the driver error code from an error.

func (Dialect) MatchErrorCode

func (d Dialect) MatchErrorCode(actualCode, targetCode string) bool

MatchErrorCode checks if an actual database error matches a catch block error code.

func (Dialect) Name

func (d Dialect) Name() string

Name returns the canonical name of the dialect.

func (Dialect) Placeholder

func (d Dialect) Placeholder(index int, name string) string

Placeholder returns the driver parameter placeholder for the given zero-based index.

type Manager

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

Manager manages the thread-safe lifecycle and retrieval of active database connection pools.

func NewManager

func NewManager() *Manager

NewManager initializes an empty connection pool manager.

func (*Manager) Close

func (m *Manager) Close() error

Close gracefully closes all active database pools.

func (*Manager) Get

func (m *Manager) Get(keyOrRef string) (*Pool, bool)

Get retrieves an active pool by short key ("postgres.main") or full reference ("connection.postgres.main").

func (*Manager) Open

func (m *Manager) Open(ctx context.Context, cfg Config) error

Open initializes a connection pool, applies tuning bounds, pings with a timeout, and registers it.

type Pool

type Pool struct {
	DB      *sql.DB
	Dialect Dialect
	Config  Config
}

Pool wraps an active database connection pool with dialect handling.

func (*Pool) Execute

func (p *Pool) Execute(ctx context.Context, query string, args map[string]any) (*QueryResult, error)

Execute runs a parameterized SQL query or mutation on the pool and returns normalized rows.

type PoolConfig

type PoolConfig struct {
	MaxOpen     int
	MaxIdle     int
	MaxLifetime time.Duration
	IdleTimeout time.Duration
}

PoolConfig defines connection pool capacity and lifecycle durations.

func DefaultPoolConfig

func DefaultPoolConfig() PoolConfig

DefaultPoolConfig returns baseline production connection pool settings.

type QueryResult

type QueryResult struct {
	Rows         []map[string]any
	Row          map[string]any
	RowsAffected int64
}

QueryResult holds extracted rows, single row pointer, and affected rows count.

Jump to

Keyboard shortcuts

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