Add Slice alongside Dict
This commit is contained in:
@@ -227,6 +227,32 @@ func (t *Array) Push(v TypedValue) {
|
||||
t.value = append(t.value, v)
|
||||
}
|
||||
|
||||
func (t *Array) Slice() []interface{} {
|
||||
rr := make([]interface{}, len(t.GetValue()))
|
||||
for i, v := range t.GetValue() {
|
||||
switch v := v.(type) {
|
||||
case Dict:
|
||||
rr[i] = v.Dict()
|
||||
|
||||
case Slice:
|
||||
rr[i] = v.Slice()
|
||||
|
||||
case TypedValue:
|
||||
tmp := v.Get()
|
||||
if d, is := tmp.(Dict); is {
|
||||
rr[i] = d.Dict()
|
||||
} else {
|
||||
rr[i] = tmp
|
||||
}
|
||||
|
||||
default:
|
||||
rr[i] = v
|
||||
}
|
||||
}
|
||||
|
||||
return rr
|
||||
}
|
||||
|
||||
// Select is field accessor for *types.Array
|
||||
//
|
||||
// Similar to SelectGVal but returns typed values
|
||||
|
||||
@@ -47,6 +47,10 @@ type (
|
||||
Dict interface {
|
||||
Dict() map[string]interface{}
|
||||
}
|
||||
|
||||
Slice interface {
|
||||
Slice() []interface{}
|
||||
}
|
||||
)
|
||||
|
||||
func UntypedValue(val interface{}) interface{} {
|
||||
|
||||
+6
-2
@@ -5,11 +5,12 @@ import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/PaesslerAG/gval"
|
||||
"github.com/cortezaproject/corteza-server/pkg/errors"
|
||||
"github.com/spf13/cast"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (t Vars) Len() int {
|
||||
@@ -134,6 +135,9 @@ func (t *Vars) Dict() map[string]interface{} {
|
||||
case Dict:
|
||||
dict[k] = v.Dict()
|
||||
|
||||
case Slice:
|
||||
dict[k] = v.Slice()
|
||||
|
||||
case TypedValue:
|
||||
tmp := v.Get()
|
||||
if d, is := tmp.(Dict); is {
|
||||
|
||||
Reference in New Issue
Block a user