sharedtx

package
v0.0.0-...-862f905 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SharedSubTx

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

SharedSubTx wraps a pgx.Tx such that it unlocks SharedTx when it commits or rolls back.

func (*SharedSubTx) Begin

func (tx *SharedSubTx) Begin(ctx context.Context) (pgx.Tx, error)

func (*SharedSubTx) Commit

func (tx *SharedSubTx) Commit(ctx context.Context) error

func (*SharedSubTx) Conn

func (tx *SharedSubTx) Conn() *pgx.Conn

func (*SharedSubTx) CopyFrom

func (tx *SharedSubTx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*SharedSubTx) Exec

func (tx *SharedSubTx) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)

func (*SharedSubTx) LargeObjects

func (tx *SharedSubTx) LargeObjects() pgx.LargeObjects

func (*SharedSubTx) Prepare

func (tx *SharedSubTx) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*SharedSubTx) Query

func (tx *SharedSubTx) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)

func (*SharedSubTx) QueryRow

func (tx *SharedSubTx) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

func (*SharedSubTx) Rollback

func (tx *SharedSubTx) Rollback(ctx context.Context) error

func (*SharedSubTx) SendBatch

func (tx *SharedSubTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

type SharedTx

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

SharedTx can be used to wrap a test transaction in cases where multiple callers may want to access it concurrently during the course of a single test case. Normally this is not allowed and an access will error with "conn busy" if another caller is already using it.

This is a test-only construct because in non-test environments an executor is a full connection pool which can support concurrent access without trouble. Many test cases use single test transactions, and that's where code written to use a connection pool can become problematic.

SharedTx uses a channel for synchronization and does *not* guarantee FIFO ordering for callers.

Avoid using SharedTx if possible because while it works, problems encountered by use of concurrent accesses will be more difficult to debug than otherwise, so it's better to not go there at all if it can be avoided.

func NewSharedTx

func NewSharedTx(tx pgx.Tx) *SharedTx

func (*SharedTx) Begin

func (e *SharedTx) Begin(ctx context.Context) (pgx.Tx, error)

func (*SharedTx) CopyFrom

func (e *SharedTx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*SharedTx) Exec

func (e *SharedTx) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)

func (*SharedTx) Query

func (e *SharedTx) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)

func (*SharedTx) QueryRow

func (e *SharedTx) QueryRow(ctx context.Context, query string, args ...any) pgx.Row

type SharedTxRow

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

SharedTxRow wraps a pgx.Row such that it unlocks SharedExecutor when the row finishes scanning.

func (*SharedTxRow) Scan

func (r *SharedTxRow) Scan(dest ...any) error

type SharedTxRows

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

SharedTxRows wraps a pgx.Rows such that it unlocks SharedExecutor when the rows are closed.

func (*SharedTxRows) Close

func (r *SharedTxRows) Close()

func (*SharedTxRows) CommandTag

func (r *SharedTxRows) CommandTag() pgconn.CommandTag

All of these are simple pass throughs.

func (*SharedTxRows) Conn

func (r *SharedTxRows) Conn() *pgx.Conn

func (*SharedTxRows) Err

func (r *SharedTxRows) Err() error

func (*SharedTxRows) FieldDescriptions

func (r *SharedTxRows) FieldDescriptions() []pgconn.FieldDescription

func (*SharedTxRows) Next

func (r *SharedTxRows) Next() bool

func (*SharedTxRows) RawValues

func (r *SharedTxRows) RawValues() [][]byte

func (*SharedTxRows) Scan

func (r *SharedTxRows) Scan(dest ...any) error

func (*SharedTxRows) Values

func (r *SharedTxRows) Values() ([]interface{}, error)

Jump to

Keyboard shortcuts

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