Documentation
¶
Overview ¶
Package batch holds the per-record upsert pipeline and result handling shared by the bulk gRPC handlers.
Index ¶
Constants ¶
const ( Written = authpb.UpsertResult_REASON_WRITTEN Invalid = authpb.UpsertResult_REASON_INVALID Duplicate = authpb.UpsertResult_REASON_DUPLICATE ClientNotFound = authpb.UpsertResult_REASON_CLIENT_NOT_FOUND ClientMismatch = authpb.UpsertResult_REASON_CLIENT_MISMATCH )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reason ¶
type Reason = authpb.UpsertResult_Reason
Reason is a record's outcome: written, or why it was refused.
type Results ¶
type Results struct {
// contains filtered or unexported fields
}
Results holds one result per request record, in input order. A record is accepted until refused. Upsert builds and fills it.
func Upsert ¶
func Upsert(n int, p UpsertPipeline) (*Results, error)
Upsert runs the per-record pipeline for one bulk call of n records and returns their results. It protovalidates each record, domain-validates each still-accepted record when Validate is set, refuses later duplicates by key when Key is set, then writes the accepted records once and maps the per-record write errors back to request positions.
A Write error is returned unchanged. Upsert also returns an error when Write returns a non-nil slice of the wrong length or a per-record error that Reason cannot map. On any error the results are nil.
func (*Results) Proto ¶
func (r *Results) Proto() []*authpb.UpsertResult
Proto returns the per-record results in input order.
type UpsertPipeline ¶
type UpsertPipeline struct {
Validator protovalidate.Validator
// Message returns record i as the proto message protovalidate checks.
Message func(i int) proto.Message
// Validate applies the domain rules to record i and returns nil when it is
// valid. It may be nil when Write applies the rules and reports a refusal per record.
Validate func(i int) error
// Key returns the field name and value that make record i a duplicate.
// Nil when repeated records are legal, as when the write folds them.
Key func(i int) (name, value string)
// Write stores the accepted records in one call. A nil slice means every
// record was written; otherwise errs[k] belongs to accepted[k].
Write func(accepted []int) (errs []error, err error)
// Reason maps a per-record write error to a refusal. It returns Written
// for an error it does not know. It may be nil when Write never returns
// per-record errors.
Reason func(err error) (reason Reason, message string)
}
UpsertPipeline holds the per-RPC steps of one bulk upsert. Message, Validate and Key take the record's position in the request.