3
0

Add Slice alongside Dict

This commit is contained in:
Tomaž Jerman
2021-04-02 13:32:07 +02:00
parent e5578d3d94
commit 1f6a83280b
3 changed files with 36 additions and 2 deletions
+26
View File
@@ -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
+4
View File
@@ -47,6 +47,10 @@ type (
Dict interface {
Dict() map[string]interface{}
}
Slice interface {
Slice() []interface{}
}
)
func UntypedValue(val interface{}) interface{} {
+6 -2
View File
@@ -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 {