batch

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create[T any](ctx context.Context, p *TracerConnection, models []*T, opts ...CreateOpts) (err error)

Create batch-inserts the given models into the database using a single INSERT statement. By default, the models are either all created or none. If WithPartialInserts is passed as an option, partial inserts are supported, and the models that could not be inserted are returned in an PartialConflictError.

func TestPersister added in v1.3.0

func TestPersister(ctx context.Context, tracer *otelx.Tracer, p persistence.Persister) func(t *testing.T)

Types

type CreateOpts added in v1.3.0

type CreateOpts func(*createOpts)
var WithPartialInserts CreateOpts = func(o *createOpts) {
	o.partialInserts = true
}

WithPartialInserts allows to insert only the models that do not conflict with an existing record. WithPartialInserts will also generate the IDs for the models before inserting them, so that the successful inserts can be correlated with the input models.

In particular, WithPartialInserts does not work with MySQL, because it does not support the "RETURNING" clause.

WithPartialInserts does not work with CockroachDB and gen_random_uuid(), because then the successful inserts cannot be correlated with the input models. Note: gen_random_uuid() will skip the UNIQUE constraint check, which needs to hit all regions in a distributed setup. Therefore, WithPartialInserts should not be used to insert models for only a single identity.

type PartialConflictError added in v1.3.0

type PartialConflictError[T any] struct {
	Failed []*T
}

PartialConflictError represents a partial conflict during Create. It always wraps a sqlcon.ErrUniqueViolation, so that the caller can either abort the whole transaction, or handle the partial success.

func (*PartialConflictError[T]) ErrOrNil added in v1.3.0

func (p *PartialConflictError[T]) ErrOrNil() error

func (*PartialConflictError[T]) Error added in v1.3.0

func (p *PartialConflictError[T]) Error() string

func (*PartialConflictError[T]) Unwrap added in v1.3.0

func (p *PartialConflictError[T]) Unwrap() error

type TracerConnection

type TracerConnection struct {
	Tracer     *otelx.Tracer
	Connection *pop.Connection
}

Jump to

Keyboard shortcuts

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