Modify runs the query against the given data and updates it in-place. Given data must be a pointer to a mutable data structure.
(ctx context.Context, data any, selector string, newValue any, opts ...execution.ExecuteOptionFn)
| 51 | // Modify runs the query against the given data and updates it in-place. |
| 52 | // Given data must be a pointer to a mutable data structure. |
| 53 | func Modify(ctx context.Context, data any, selector string, newValue any, opts ...execution.ExecuteOptionFn) (int, error) { |
| 54 | res, count, err := Query(ctx, data, selector, opts...) |
| 55 | if err != nil { |
| 56 | return 0, err |
| 57 | } |
| 58 | for _, v := range res { |
| 59 | if err := v.Set(model.NewValue(newValue)); err != nil { |
| 60 | return 0, err |
| 61 | } |
| 62 | } |
| 63 | return count, nil |
| 64 | } |