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
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