Skip to content
Snippets Groups Projects
Commit e09493c3 authored by Danis Kirasirov's avatar Danis Kirasirov
Browse files

add ExprMapper interface

parent 6c9d25ab
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,11 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf ...@@ -31,6 +31,11 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf
} }
for k, v := range env { for k, v := range env {
if mapper, ok := v.(ExprMapper); ok {
e[k] = mapper.ToExprMap()
continue
}
e[k] = v e[k] = v
} }
...@@ -79,3 +84,7 @@ func IsExpression(input string) bool { ...@@ -79,3 +84,7 @@ func IsExpression(input string) bool {
return false return false
} }
type ExprMapper interface {
ToExprMap() map[string]interface{}
}
\ No newline at end of file
...@@ -213,7 +213,7 @@ func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} { ...@@ -213,7 +213,7 @@ func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} {
return bson.M{c.identifier(nodeIn.Left): bson.M{"$nin": c.eval(nodeIn.Right)}} return bson.M{c.identifier(nodeIn.Left): bson.M{"$nin": c.eval(nodeIn.Right)}}
} }
return bson.M{"$not": c.compile(node.Node)} return bson.M{"$not": c.compile(node.Node)}
default: default:
panic(fmt.Sprintf("unknown operator (%v)", node.Operator)) panic(fmt.Sprintf("unknown operator (%v)", node.Operator))
} }
......
...@@ -25,6 +25,13 @@ func (r *Reference) MarshalBSON() ([]byte, error) { ...@@ -25,6 +25,13 @@ func (r *Reference) MarshalBSON() ([]byte, error) {
return bson.Marshal(d) return bson.Marshal(d)
} }
func (r *Reference) ToExprMap() map[string]interface{} {
return map[string]interface{}{
"collection_id": r.CollectionID,
"id": r.ID,
}
}
func ReferenceFromPB(refPB *pb.Reference) *Reference { func ReferenceFromPB(refPB *pb.Reference) *Reference {
if refPB == nil { if refPB == nil {
return nil return nil
...@@ -107,4 +114,4 @@ func EqualArrays(sr1, sr2 []*Reference) bool { ...@@ -107,4 +114,4 @@ func EqualArrays(sr1, sr2 []*Reference) bool {
func (r *Reference) IsValid() bool { func (r *Reference) IsValid() bool {
return r != nil && r.ID != "" && r.CollectionID != "" && !r.Disabled return r != nil && r.ID != "" && r.CollectionID != "" && !r.Disabled
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment