MCPcopy Index your code
hub / github.com/riverqueue/river / JobInsertFastMany

Method JobInsertFastMany

riverdriver/riversqlite/river_sqlite_driver.go:529–558  ·  view source on GitHub ↗
(ctx context.Context, params *riverdriver.JobInsertFastManyParams)

Source from the content-addressed store, hash-verified

527}
528
529func (e *Executor) JobInsertFastMany(ctx context.Context, params *riverdriver.JobInsertFastManyParams) ([]*riverdriver.JobInsertFastResult, error) {
530 // We use a special `(xmax != 0)` trick in Postgres to determine whether an
531 // upserted row was inserted or skipped, but as far as I can find, there's no
532 // such trick possible in SQLite. Instead, we roll a random nonce and insert
533 // it to metadata. If the same nonce comes back, we know we really inserted
534 // the row. If not, we're getting an existing row back.
535 uniqueNonce := randutil.Hex(8)
536
537 jobsParam, err := sqliteJobInsertFastManyJobsParam(params.Jobs, uniqueNonce)
538 if err != nil {
539 return nil, err
540 }
541
542 jobs, err := dbsqlc.New().JobInsertFastMany(schemaTemplateParam(ctx, params.Schema), e.dbtx, jobsParam)
543 if err != nil {
544 return nil, interpretError(err)
545 }
546
547 return sliceutil.MapError(jobs, func(internal *dbsqlc.RiverJob) (*riverdriver.JobInsertFastResult, error) {
548 job, err := jobRowFromInternal(internal)
549 if err != nil {
550 return nil, err
551 }
552
553 return &riverdriver.JobInsertFastResult{
554 Job: job,
555 UniqueSkippedAsDuplicate: gjson.GetBytes(job.Metadata, rivercommon.MetadataKeyUniqueNonce).Str != uniqueNonce,
556 }, nil
557 })
558}
559
560func (e *Executor) JobInsertFastManyNoReturning(ctx context.Context, params *riverdriver.JobInsertFastManyParams) (int, error) {
561 jobsParam, err := sqliteJobInsertFastManyJobsParam(params.Jobs, "")

Callers

nothing calls this directly

Implementers 3

Executorriverdriver/riverpgxv5/river_pgx_v5_dr
Executorriverdriver/riverdatabasesql/river_dat
Executorriverdriver/riversqlite/river_sqlite_d

Calls 8

HexFunction · 0.92
NewFunction · 0.92
MapErrorFunction · 0.92
schemaTemplateParamFunction · 0.70
interpretErrorFunction · 0.70
jobRowFromInternalFunction · 0.70
JobInsertFastManyMethod · 0.65

Tested by

no test coverage detected