setReference is a helper function to upsert a reference within a transaction
(tx *gorm.DB, ref *plumbing.Reference)
| 237 | |
| 238 | // setReference is a helper function to upsert a reference within a transaction |
| 239 | func (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 | } |
no test coverage detected