Help us shape the future of Go! Take the 2026 Go Developer Survey

sequence

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

MySQL sequencing

Default: original transient transaction

PresetIDWithTransientTransaction is the default, preserving original Datly and SQLX selection. transient.go, handler.go and udf.go remain byte-for-byte unchanged from 24e180f. The generic exact-value API invokes the original NextSequence path and adapts its returned range without changing its SQL, transaction, session, locking, cleanup or retry semantics.

No allocator table is needed. Source AUTO_INCREMENT is advanced by transient source INSERTs in a separate transaction which SQLX rolls back. A caller's transaction is not completed by this operation.

The mechanism needs a spare connection when a caller already holds a transaction, and may wait on source locks held by that caller. Source defaults/triggers and applicable constraints execute. Transactional rows roll back; nontransactional or external effects need not. Original FK toggling/restoration, advisory lock names, timeout/retries and the last-bound-argument identity assumption remain unchanged. These limits are documented and tested, not repaired by this patch. go-sql-driver/mysql can invalidate the caller connection/transaction when a blocked allocation context is cancelled. SQLX does not commit or roll back that caller transaction, but it cannot promise the driver-cancelled handle remains usable. Cancellation tests therefore require an error, no committed source rows and no silent allocator-table fallback; noncancelled caller ownership has a separate positive test.

Explicit reservation option

The native InnoDB table allocator is opt-in. Provision with Store.Install(ctx, db) outside writer transactions, then pass dialect.PresetIDWithReservation to the insert/sequence service. It uses sqlx_allocator.sequence_reservations, caller-transaction row locking and no transient source INSERTs. It can operate with a single caller connection.

Runtime credentials need SELECT/INSERT/UPDATE on native metadata and source access. It honors native field mapping, increment/offset and integer bounds. Rollback can release its reservation. Unmanaged source AUTO_INCREMENT inserts do not see outstanding metadata reservations; do not mix generators. The default never switches to this optional owner when the transient mechanism fails.

Documentation

Index

Constants

View Source
const MaxSeqValue = 9223372036854775807

MaxSeqValue represents default maximum sequence value

Variables

This section is empty.

Functions

func UpdateMySQLSequence

func UpdateMySQLSequence(ctx context.Context, db *sql.DB, target interface{}, iopts ...interface{}) (doNext bool, err error)

UpdateMySQLSequence updates for all passed sink.Sequences theirs Value or StartValue getting autoincrement metadata by: SHOW CREATE TABLE ..., @@SESSION.auto_increment_increment, @@SESSION.auto_increment_offset

Warning! Until we don't use autoincrement in the table (by insert at least one row with 0-value id), "show create table" and "information_schema.tables" show wrong autoincrement value if @@SESSION.auto_increment_increment > 1

Types

type ReservationLock added in v0.26.1

type ReservationLock struct{}

ReservationLock defers row locking until native column identity is known. The InnoDB reservation uses a current locking read, including under RR.

func (*ReservationLock) CanUse added in v0.26.1

func (*ReservationLock) CanUse(...interface{}) bool

func (*ReservationLock) Handle added in v0.26.1

func (*ReservationLock) Handle(ctx context.Context, _ *sql.DB, _ interface{}, _ ...interface{}) (bool, error)

type ReservationMetadata added in v0.26.1

type ReservationMetadata struct{}

ReservationMetadata validates the physical AUTO_INCREMENT column rather than inferring an allocator from a product name or an authored primary-key tag.

func (*ReservationMetadata) CanUse added in v0.26.1

func (*ReservationMetadata) CanUse(opts ...interface{}) bool

func (*ReservationMetadata) Handle added in v0.26.1

func (m *ReservationMetadata) Handle(ctx context.Context, db *sql.DB, target interface{}, opts ...interface{}) (bool, error)

type ReservationRange added in v0.26.1

type ReservationRange struct{}

func (*ReservationRange) CanUse added in v0.26.1

func (*ReservationRange) CanUse(opts ...interface{}) bool

func (*ReservationRange) Handle added in v0.26.1

func (*ReservationRange) Handle(ctx context.Context, db *sql.DB, target interface{}, opts ...interface{}) (bool, error)

type Reserve added in v0.26.1

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

func (*Reserve) CanUse added in v0.26.1

func (*Reserve) CanUse(...interface{}) bool

func (*Reserve) Handle added in v0.26.1

func (n *Reserve) Handle(ctx context.Context, db *sql.DB, target interface{}, opts ...interface{}) (bool, error)

type Store added in v0.26.1

type Store struct{}

Store provisions native allocator metadata outside application transactions. MySQL DDL implicitly commits: allocation never invokes Install, creates source objects, modifies source schema, or borrows a second caller connection.

func (*Store) Install added in v0.26.1

func (*Store) Install(ctx context.Context, db *sql.DB) error

type StrategyError added in v0.26.1

type StrategyError struct{}

StrategyError prevents a placeholder query from pretending to allocate IDs.

func (*StrategyError) CanUse added in v0.26.1

func (*StrategyError) CanUse(...interface{}) bool

func (*StrategyError) Handle added in v0.26.1

func (*StrategyError) Handle(_ context.Context, _ *sql.DB, _ interface{}, opts ...interface{}) (bool, error)

type Transient

type Transient struct{}

Transient represents struct used to setting new autoincrement value using insert inside new transaction finished by rollback

func (*Transient) CanUse

func (n *Transient) CanUse(iopts ...interface{}) bool

CanUse returns true if Handle function can be executed

func (*Transient) Handle

func (n *Transient) Handle(ctx context.Context, db *sql.DB, target interface{}, iopts ...interface{}) (doNext bool, err error)

type Udf

type Udf struct{}

Udf represents struct used to setting new autoincrement value using user defined stored procedure in db and internal autoincrement value handling

func (*Udf) CanUse

func (n *Udf) CanUse(iopts ...interface{}) bool

CanUse returns true if Handle function can be executed

func (*Udf) Handle

func (n *Udf) Handle(ctx context.Context, db *sql.DB, target interface{}, iopts ...interface{}) (doNext bool, err error)

Handle sets new autoincrement value by executing user defined stored procedure and using internal autoincrement value handling

all this handler requires more testing (especially with transactions)

Jump to

Keyboard shortcuts

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