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 ¶
- func AcquireTableLock(ctx context.Context, db *sql.DB, config TableLockConfig, ...) error
- func GenerateOwnerID() (string, error)
- func GetApplied(ctx context.Context, d *Driver, querier Queryer) ([]queen.Applied, error)
- func ParseTimeISO8601(src any) (time.Time, error)
- func PlaceholderAtSign(n int) string
- func PlaceholderDollar(n int) string
- func PlaceholderQuestion(n int) string
- func QuoteBackticks(name string) string
- func QuoteBrackets(name string) string
- func QuoteDoubleQuotes(name string) string
- func QuoteIdentifier(name string, quoteChar QuoteChar) string
- func RecordOn(ctx context.Context, d *Driver, execer Execer, m *queen.Migration, ...) error
- func RecordTx(ctx context.Context, d *Driver, tx *sql.Tx, m *queen.Migration, ...) error
- func RemoveOn(ctx context.Context, d *Driver, execer Execer, version string) error
- func RemoveTx(ctx context.Context, d *Driver, tx *sql.Tx, version string) error
- type Config
- type Driver
- func (d *Driver) Close() error
- func (d *Driver) Exec(ctx context.Context, isolationLevel sql.IsolationLevel, fn func(*sql.Tx) error) error
- func (d *Driver) GetApplied(ctx context.Context) ([]queen.Applied, error)
- func (d *Driver) Record(ctx context.Context, m *queen.Migration, meta *queen.MigrationMetadata) error
- func (d *Driver) Remove(ctx context.Context, version string) error
- func (d *Driver) SQLDB() *sql.DB
- type Execer
- type Queryer
- type QuoteChar
- type TableLockConfig
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 ¶
GenerateOwnerID generates a unique owner identifier for lock ownership tracking.
func GetApplied ¶
GetApplied reads migration history through a specific database connection.
func ParseTimeISO8601 ¶
ParseTimeISO8601 parses common SQLite timestamp and ISO-8601 string formats.
func PlaceholderAtSign ¶
PlaceholderAtSign creates placeholders in the format @p1, @p2, @p3... Used for MS SQL Server which requires named parameters.
func PlaceholderDollar ¶
PlaceholderDollar creates placeholders in the format $1, $2, $3...
func PlaceholderQuestion ¶
PlaceholderQuestion creates placeholders in the format ?, ?, ?...
func QuoteBackticks ¶
QuoteBackticks is a convenience wrapper for QuoteIdentifier with Backtick.
func QuoteBrackets ¶
QuoteBrackets is a convenience wrapper for QuoteIdentifier with Bracket.
func QuoteDoubleQuotes ¶
QuoteDoubleQuotes is a convenience wrapper for QuoteIdentifier with DoubleQuote.
func QuoteIdentifier ¶
QuoteIdentifier escapes and wraps a SQL identifier using the provided quote character.
func RecordOn ¶
func RecordOn(ctx context.Context, d *Driver, execer Execer, m *queen.Migration, meta *queen.MigrationMetadata) error
RecordOn records a migration through a specific database connection.
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.
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 ¶
Driver holds the shared database handle and migration-table helpers.
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 ¶
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.
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)
// RetryableInsertError reports whether a failed insert means another
// contender won the lock race and acquisition should be retried.
RetryableInsertError func(error) bool
}
TableLockConfig configures table-based distributed locking.