dynamo-browse/internal/dynamo-browse/models/queryexpr/builtins.go
Leon Mika 917663fac0
Issue 33: Finished most aspects of the expression language (#38)
- Most aspects of scans and queries can now be represented using the expression language
- All constructs of the expression language can be used to evaluate items
2022-11-18 07:31:15 +11:00

40 lines
1 KiB
Go

package queryexpr
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/pkg/errors"
"strconv"
)
type nativeFunc func(ctx context.Context, args []types.AttributeValue) (types.AttributeValue, error)
var nativeFuncs = map[string]nativeFunc{
"size": func(ctx context.Context, args []types.AttributeValue) (types.AttributeValue, error) {
if len(args) != 1 {
return nil, InvalidArgumentNumberError{Name: "size", Expected: 1, Actual: len(args)}
}
var l int
switch t := args[0].(type) {
case *types.AttributeValueMemberB:
l = len(t.Value)
case *types.AttributeValueMemberS:
l = len(t.Value)
case *types.AttributeValueMemberL:
l = len(t.Value)
case *types.AttributeValueMemberM:
l = len(t.Value)
case *types.AttributeValueMemberSS:
l = len(t.Value)
case *types.AttributeValueMemberNS:
l = len(t.Value)
case *types.AttributeValueMemberBS:
l = len(t.Value)
default:
return nil, errors.New("cannot take size of arg")
}
return &types.AttributeValueMemberN{Value: strconv.Itoa(l)}, nil
},
}