MCPcopy
hub / github.com/TomWright/dasel / Query

Function Query

api.go:11–31  ·  view source on GitHub ↗

Query queries the data using the selector and returns the results.

(ctx context.Context, data any, selector string, opts ...execution.ExecuteOptionFn)

Source from the content-addressed store, hash-verified

9
10// Query queries the data using the selector and returns the results.
11func 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.

Callers 2

SelectFunction · 0.85
ModifyFunction · 0.85

Calls 6

NewOptionsFunction · 0.92
NewValueFunction · 0.92
ExecuteSelectorFunction · 0.92
IsBranchMethod · 0.80
IsSpreadMethod · 0.80
RangeSliceMethod · 0.80

Tested by

no test coverage detected