MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / Save

Method Save

stores/universally/commit/store.go:89–118  ·  view source on GitHub ↗
(ctx context.Context, key string, target string, commit *H)

Source from the content-addressed store, hash-verified

87)
88
89func (h *Store[H]) Save(ctx context.Context, key string, target string, commit *H) error {
90 hid := uuid.NewString()
91 ho := &Commit[H]{
92 Id: 0,
93 UUID: hid,
94 Target: target,
95 Key: key,
96 Data: commit,
97 CreateAt: time.Now(),
98 }
99 lo := &Latest{
100 Id: 0,
101 Target: target,
102 Key: key,
103 Latest: hid,
104 }
105
106 return h.db.DB(ctx).Transaction(func(tx *gorm.DB) error {
107 err := tx.Table(h.commitTableName).Create(ho).Error
108 if err != nil {
109 return err
110 }
111
112 return tx.Table(h.latestTableName).Clauses(clause.OnConflict{
113 Columns: latestUniques,
114 UpdateAll: true,
115 }).Create(lo).Error
116
117 })
118}
119func (h *Store[H]) Latest(ctx context.Context, key string, target ...string) ([]*Commit[H], error) {
120
121 wheres := make([]string, 0, 2)

Callers

nothing calls this directly

Calls 1

CreateMethod · 0.65

Tested by

no test coverage detected