Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for equality query on key field #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions action/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func convertToDatastoreQuery(namespace string, s *gql.SelectExpr) (string, *data
}

// Filter
q, err := setFilter(q, s.Where)
q, err := setFilter(q, s.Where, namespace)
if err != nil {
return "", nil, err
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func convertToDatastoreQuery(namespace string, s *gql.SelectExpr) (string, *data
return kind, q, nil
}

func setFilter(q *datastore.Query, where []gql.ConditionExpr) (*datastore.Query, error) {
func setFilter(q *datastore.Query, where []gql.ConditionExpr, namespace string) (*datastore.Query, error) {

for _, c := range where {
switch c.GetComparator() {
Expand Down Expand Up @@ -210,7 +210,11 @@ func setFilter(q *datastore.Query, where []gql.ConditionExpr) (*datastore.Query,
}

case gql.OP_EQUALS:
q = q.Filter(fmt.Sprintf("%s =", c.GetPropertyName()), c.GetValue().V)
v := c.GetValue().V
if key, ok := v.(gql.KeyLiteralExpr); ok {
v = key.ToDatastoreKey(namespace)
}
q = q.Filter(fmt.Sprintf("%s =", c.GetPropertyName()), v)

case gql.OP_LESS:
q = q.Filter(fmt.Sprintf("%s <", c.GetPropertyName()), c.GetValue().V)
Expand Down
Loading