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

Method SetIndex

pkg/cache/postgres/index.go:19–35  ·  view source on GitHub ↗

SetIndex serializes and stores the index in Postgres.

(idx *index.Index)

Source from the content-addressed store, hash-verified

17
18// SetIndex serializes and stores the index in Postgres.
19func (s *IndexStorage) SetIndex(idx *index.Index) error {
20 data, err := json.Marshal(idx)
21 if err != nil {
22 return err
23 }
24
25 index := &database.Index{
26 URL: s.namespacePrefix,
27 Blob: data,
28 }
29
30 // Upsert operation: Update if exists, else create
31 return s.db.Clauses(clause.OnConflict{
32 Columns: []clause.Column{{Name: "url"}}, // conflict target
33 DoUpdates: clause.Assignments(map[string]interface{}{"blob": data}), // update just the blob
34 }).Create(index).Error
35}
36
37// Index retrieves and deserializes the index from Postgres.
38func (s *IndexStorage) Index() (*index.Index, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected