SetIndex serializes and stores the index in Postgres.
(idx *index.Index)
| 17 | |
| 18 | // SetIndex serializes and stores the index in Postgres. |
| 19 | func (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. |
| 38 | func (s *IndexStorage) Index() (*index.Index, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected