Skip to content

Commit

Permalink
docstore/all: Add in/not-in operators for Query
Browse files Browse the repository at this point in the history
Authored-by: Cory Schwartz <[email protected]>
  • Loading branch information
vangent authored and ybourgery committed Jan 25, 2024
1 parent 9319caf commit 7e11491
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 573 deletions.
16 changes: 16 additions & 0 deletions docstore/awsdynamodb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"io"
"reflect"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -436,11 +437,26 @@ func toFilter(f driver.Filter) expression.ConditionBuilder {
return expression.GreaterThanEqual(name, val)
case ">":
return expression.GreaterThan(name, val)
case "in":
return toInCondition(f)
case "not-in":
return expression.Not(toInCondition(f))
default:
panic(fmt.Sprint("invalid filter operation:", f.Op))
}
}

func toInCondition(f driver.Filter) expression.ConditionBuilder {
name := expression.Name(strings.Join(f.FieldPath, "."))
vslice := reflect.ValueOf(f.Value)
right := expression.Value(vslice.Index(0).Interface())
other := make([]expression.OperandBuilder, vslice.Len()-1)
for i := 1; i < vslice.Len(); i++ {
other[i-1] = expression.Value(vslice.Index(i).Interface())
}
return expression.In(name, right, other...)
}

type documentIterator struct {
qr *queryRunner
items []map[string]*dyn.AttributeValue
Expand Down
Loading

0 comments on commit 7e11491

Please sign in to comment.