Query queries the data using the selector and returns the results.
(ctx context.Context, data any, selector string, opts ...execution.ExecuteOptionFn)
| 9 | |
| 10 | // Query queries the data using the selector and returns the results. |
| 11 | func Query(ctx context.Context, data any, selector string, opts ...execution.ExecuteOptionFn) ([]*model.Value, int, error) { |
| 12 | options := execution.NewOptions(opts...) |
| 13 | val := model.NewValue(data) |
| 14 | out, err := execution.ExecuteSelector(ctx, selector, val, options) |
| 15 | if err != nil { |
| 16 | return nil, 0, err |
| 17 | } |
| 18 | |
| 19 | if out.IsBranch() || out.IsSpread() { |
| 20 | res := make([]*model.Value, 0) |
| 21 | if err := out.RangeSlice(func(i int, v *model.Value) error { |
| 22 | res = append(res, v) |
| 23 | return nil |
| 24 | }); err != nil { |
| 25 | return nil, 0, err |
| 26 | } |
| 27 | return res, len(res), nil |
| 28 | } |
| 29 | |
| 30 | return []*model.Value{out}, 1, nil |
| 31 | } |
| 32 | |
| 33 | // Select queries the data using the selector and returns the results as native Go types. |
| 34 | // Ordering within maps is not guaranteed. |
no test coverage detected