Chromium Code Reviews| 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 |
| } |
| } |