base

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 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

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

AcquireTableLock retries a table-backed lock until it is acquired or times out.

func GenerateOwnerID

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 common SQLite timestamp and ISO-8601 string formats.

func PlaceholderAtSign

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

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.

func RecordTx

func RecordTx(ctx context.Context, d *Driver, tx *sql.Tx, m *queen.Migration, meta *queen.MigrationMetadata) error

RecordTx marks a migration as applied using tx. Concrete drivers can expose this through queen.TransactionalRecorder when their database supports it.

func RemoveTx

func RemoveTx(ctx context.Context, d *Driver, tx *sql.Tx, version string) error

RemoveTx removes a migration record using tx. Concrete drivers can expose this through queen.TransactionalRecorder when their database supports it.

Types

type Config

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

Config contains configuration for the base driver.

type Driver

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

Driver holds the shared database handle and migration-table helpers.

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.

func (*Driver) SQLDB

func (d *Driver) SQLDB() *sql.DB

SQLDB exposes the underlying database handle for optional diagnostics.

type QuoteChar

type QuoteChar string

QuoteChar represents a SQL identifier quote character.

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

type TableLockConfig

type TableLockConfig struct {
	CleanupQuery string
	CleanupArgs  func(lockKey string, expiresAt time.Time) []any
	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