MCPcopy Create free account
hub / github.com/encoder-run/operator / setReference

Method setReference

pkg/cache/postgres/reference.go:239–253  ·  view source on GitHub ↗

setReference is a helper function to upsert a reference within a transaction

(tx *gorm.DB, ref *plumbing.Reference)

Source from the content-addressed store, hash-verified

237
238// setReference is a helper function to upsert a reference within a transaction
239func (r *ReferenceStorage) setReference(tx *gorm.DB, ref *plumbing.Reference) error {
240 reference := &database.Reference{
241 Name: ref.Name().String(),
242 Type: ref.Type().String(),
243 Target: ref.Target().String(),
244 Hash: ref.Hash().String(),
245 URL: r.namespacePrefix,
246 }
247
248 // Upsert operation: Update if exists, else create
249 return tx.Clauses(clause.OnConflict{
250 Columns: []clause.Column{{Name: "url"}, {Name: "name"}}, // conflict target
251 DoUpdates: clause.Assignments(map[string]interface{}{"hash": ref.Hash().String(), "type": ref.Type().String(), "target": ref.Target().String()}), // update fields
252 }).Create(reference).Error
253}

Callers 1

CheckAndSetReferenceMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected