| 33 | } |
| 34 | |
| 35 | func (i *imlSettingStore) Set(ctx context.Context, name string, value string, operator string) error { |
| 36 | return i.Store.Transaction(ctx, func(ctx context.Context) error { |
| 37 | v, err := i.Store.First(ctx, map[string]interface{}{"name": name}) |
| 38 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 39 | return err |
| 40 | } |
| 41 | if v == nil { |
| 42 | v = &Setting{ |
| 43 | Name: name, |
| 44 | CreateAt: time.Now(), |
| 45 | UpdateAt: time.Now(), |
| 46 | Value: value, |
| 47 | Operator: operator, |
| 48 | } |
| 49 | return i.Store.Insert(ctx, v) |
| 50 | } |
| 51 | v.Value = value |
| 52 | v.Operator = operator |
| 53 | v.UpdateAt = time.Now() |
| 54 | _, err = i.Store.Update(ctx, v) |
| 55 | return err |
| 56 | |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | func init() { |
| 61 | autowire.Auto[ISettingStore](func() reflect.Value { |