sqllock

package
v0.0.0-...-ab837b8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqllock implements the shared SQL lock algorithm for dialect modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct{ Table, KeyColumn, OwnerColumn, ExpiryColumn string }

Config maps a dedicated lock table. Empty identifiers select defaults.

type Store

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

Store is a dialect-specific SQL backend; the caller owns the database connection.

func New

func New(db *sql.DB, dialect string, c Config) (*Store, error)

New validates the table mapping and constructs a store.

func (*Store) Acquire

func (s *Store) Acquire(ctx context.Context, key, owner string, ttl time.Duration) (bool, error)

Acquire inserts a placeholder and conditionally takes an expired lock in one short transaction. No transaction or connection remains held during user work.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate creates the configured table explicitly. It never changes existing rows.

func (*Store) MigrationSQL

func (s *Store) MigrationSQL() string

MigrationSQL returns idempotent DDL for the configured dedicated table.

func (*Store) Release

func (s *Store) Release(ctx context.Context, key, owner string) error

Release removes only the supplied owner's record.

func (*Store) Renew

func (s *Store) Renew(ctx context.Context, key, owner string, ttl time.Duration) (bool, error)

Renew conditionally extends an unexpired owner's lock using database time.

Jump to

Keyboard shortcuts

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