base

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package base provides common functionality for Queen database drivers.

Package base provides common functionality for database drivers.

Package base provides common functionality for database drivers.

Package base provides common functionality for database drivers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireTableLock added in v0.2.0

func AcquireTableLock(ctx context.Context, db *sql.DB, config TableLockConfig, lockKey, ownerID string, timeout time.Duration) error

AcquireTableLock implements distributed locking using a lock table. Retries with exponential backoff until lock is acquired or timeout is reached.

func GenerateOwnerID added in v0.2.0

func GenerateOwnerID() (string, error)

GenerateOwnerID generates a unique owner identifier for lock ownership tracking.

func ParseTimeISO8601

func ParseTimeISO8601(src any) (time.Time, error)

ParseTimeISO8601 parses time from ISO8601 string format.

func PlaceholderAtSign added in v0.3.0

func PlaceholderAtSign(n int) string

PlaceholderAtSign creates placeholders in the format @p1, @p2, @p3... Used for MS SQL Server which requires named parameters.

func PlaceholderDollar

func PlaceholderDollar(n int) string

PlaceholderDollar creates placeholders in the format $1, $2, $3...

func PlaceholderQuestion

func PlaceholderQuestion(n int) string

PlaceholderQuestion creates placeholders in the format ?, ?, ?...

func QuoteBackticks

func QuoteBackticks(name string) string

QuoteBackticks is a convenience wrapper for QuoteIdentifier with Backtick.

func QuoteBrackets added in v0.2.0

func QuoteBrackets(name string) string

QuoteBrackets is a convenience wrapper for QuoteIdentifier with Bracket.

func QuoteDoubleQuotes

func QuoteDoubleQuotes(name string) string

QuoteDoubleQuotes is a convenience wrapper for QuoteIdentifier with DoubleQuote.

func QuoteIdentifier

func QuoteIdentifier(name string, quoteChar QuoteChar) string

QuoteIdentifier escapes and wraps a SQL identifier using the provided quote character.

Types

type Config

type Config struct {
	Placeholder     func(n int) string
	QuoteIdentifier func(name string) string
	ParseTime       func(src interface{}) (time.Time, error)
}

Config contains configuration for the base driver.

type Driver

type Driver struct {
	DB        *sql.DB
	TableName string
	Config    Config
}

Driver provides a base implementation of common queen.Driver methods. Concrete drivers should embed this type and implement Init() and Lock()/Unlock().

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) Exec

func (d *Driver) Exec(ctx context.Context, isolationLevel sql.IsolationLevel, fn func(*sql.Tx) error) error

Exec executes a function within a transaction with the specified isolation level.

func (*Driver) GetApplied

func (d *Driver) GetApplied(ctx context.Context) ([]queen.Applied, error)

GetApplied returns all applied migrations sorted by applied_at.

func (*Driver) Record

func (d *Driver) Record(ctx context.Context, m *queen.Migration, meta *queen.MigrationMetadata) error

Record marks a migration as applied in the database.

func (*Driver) Remove

func (d *Driver) Remove(ctx context.Context, version string) error

Remove removes a migration record from the database.

type QuoteChar

type QuoteChar string

QuoteChar represents a SQL identifier quote character.

const (
	DoubleQuote QuoteChar = `"`
	Backtick    QuoteChar = "`"
	Bracket     QuoteChar = `[]`
)

type TableLockConfig added in v0.2.0

type TableLockConfig struct {
	CleanupQuery string
	CheckQuery   string
	InsertQuery  string
	ScanFunc     func(*sql.Row) (bool, error)
}

TableLockConfig configures table-based distributed locking.

Jump to

Keyboard shortcuts

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