SetReference stores a reference in Postgres.
(ref *plumbing.Reference)
| 19 | |
| 20 | // SetReference stores a reference in Postgres. |
| 21 | func (r *ReferenceStorage) SetReference(ref *plumbing.Reference) error { |
| 22 | reference := &database.Reference{ |
| 23 | Name: ref.Name().String(), |
| 24 | Type: ref.Type().String(), |
| 25 | Target: ref.Target().String(), |
| 26 | Hash: ref.Hash().String(), |
| 27 | URL: r.namespacePrefix, |
| 28 | } |
| 29 | |
| 30 | // Upsert operation: Update if exists, else create |
| 31 | return r.db.Clauses(clause.OnConflict{ |
| 32 | Columns: []clause.Column{{Name: "url"}, {Name: "name"}}, // conflict target |
| 33 | DoUpdates: clause.Assignments(map[string]interface{}{"hash": ref.Hash().String()}), // update just the hash |
| 34 | }).Create(reference).Error |
| 35 | } |
| 36 | |
| 37 | // Reference retrieves a reference from Postgres by its name. |
| 38 | func (r *ReferenceStorage) Reference(name plumbing.ReferenceName) (*plumbing.Reference, error) { |