Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Unified Diff: service/datastore/index.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: inequalities work now Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: service/datastore/index.go
diff --git a/service/datastore/index.go b/service/datastore/index.go
index 0f1aaca469903e6cef8ba46bda5073dbb22f61f9..66f39c6f8e59f0ba6fe9e260c576a56d7a9f6177 100644
--- a/service/datastore/index.go
+++ b/service/datastore/index.go
@@ -18,6 +18,13 @@ const (
DESCENDING = true
)
+func (i IndexDirection) String() string {
+ if i == ASCENDING {
+ return "ASCENDING"
+ }
+ return "DESCENDING"
+}
+
type IndexColumn struct {
Property string
Direction IndexDirection
@@ -39,6 +46,33 @@ type IndexDefinition struct {
SortBy []IndexColumn
}
+func (id *IndexDefinition) Equal(o *IndexDefinition) bool {
dnj (Google) 2015/08/23 06:50:07 Does "gofmt" really not complain about a lack of c
iannucci 2015/08/23 18:19:43 yeah I haven't been running golint on this repo (g
+ if id.Kind != o.Kind || id.Ancestor != o.Ancestor || len(id.SortBy) != len(o.SortBy) {
+ return false
+ }
+ for i, col := range id.SortBy {
+ if col != o.SortBy[i] {
+ return false
+ }
+ }
+ return true
+}
+
+// NormalizeOrder returns the normalized SortBy value for this IndexDefinition.
+// This includes prepending __ancestor__ (if id.Ancestor is true), and appending
+// __key__ if it's not explicitly the last field in this IndexDefinition.
+func (id *IndexDefinition) NormalizeOrder() []IndexColumn {
+ ret := make([]IndexColumn, 0, len(id.SortBy))
+ if id.Ancestor {
+ ret = append(ret, IndexColumn{Property: "__ancestor__"})
+ }
+ ret = append(ret, id.SortBy...)
+ if len(ret) == 0 || ret[len(ret)-1].Property != "__key__" {
+ ret = append(ret, IndexColumn{Property: "__key__"})
+ }
+ return ret
+}
+
// Yeah who needs templates, right?
// <flames>This is fine.</flames>
@@ -119,7 +153,7 @@ func (i *IndexDefinition) Compound() bool {
return false
}
for _, sb := range i.SortBy {
- if sb.Property == "" {
+ if sb.Property == "" || sb.Property == "__ancestor__" {
return false
}
}

Powered by Google App Engine
This is Rietveld 408576698