serial

package
v0.0.0-...-4dcfcdd Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package serial allows an otherwise-concurrent use of a database pool to be transparently deoptimized into serial use of a single transaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	Pool *pgxpool.Pool
	// contains filtered or unexported fields
}

Pool is a wrapper around a database connection pool that concentrates database queries into a single transaction. This type is used when it is necessary to de-optimize concurrent database performance in favor of transactional consistency.

This type is internally synchronized, and the query method calls will block each other. Queries will also be blocked while there is an active pgx.Rows or un-scanned pgx.Row that has been returned from a query.

func (*Pool) Begin

func (s *Pool) Begin(ctx context.Context) error

Begin opens a new transaction to concentrate work into.

func (*Pool) Commit

func (s *Pool) Commit(ctx context.Context) error

Commit commits the underlying transaction.

func (*Pool) Exec

func (s *Pool) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

Exec implements types.StagingQuerier and can only be called after Begin.

func (*Pool) Query

func (s *Pool) Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error)

Query implements types.StagingQuerier and can only be called after Begin. The Rows that are returned from this method must be closed, fully consumed, or encounter an error before other query methods will be allowed to proceed.

func (*Pool) QueryRow

func (s *Pool) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row

QueryRow implements types.StagingQuerier and can only be called after Begin. The Row that is returned must be scanned before any other query methods wil be allowed to proceed.

func (*Pool) Rollback

func (s *Pool) Rollback(ctx context.Context) error

Rollback abort the underlying transaction, if one is present. This method is always safe to call.

Jump to

Keyboard shortcuts

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