Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package datastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // indexes. | 210 // indexes. |
| 211 func (id *IndexDefinition) Builtin() bool { | 211 func (id *IndexDefinition) Builtin() bool { |
| 212 return !id.Ancestor && len(id.SortBy) <= 1 | 212 return !id.Ancestor && len(id.SortBy) <= 1 |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Compound returns true iff this IndexDefinition is a valid compound index | 215 // Compound returns true iff this IndexDefinition is a valid compound index |
| 216 // definition. | 216 // definition. |
| 217 // | 217 // |
| 218 // NOTE: !Builtin() does not imply Compound(). | 218 // NOTE: !Builtin() does not imply Compound(). |
| 219 func (id *IndexDefinition) Compound() bool { | 219 func (id *IndexDefinition) Compound() bool { |
| 220 » if id.Kind == "" || len(id.SortBy) <= 1 { | 220 » if id.Kind == "" || id.Builtin() { |
|
iannucci
2015/09/29 04:43:28
duplicate logic is duplicate.
| |
| 221 return false | 221 return false |
| 222 } | 222 } |
| 223 for _, sb := range id.SortBy { | 223 for _, sb := range id.SortBy { |
| 224 if sb.Property == "" || sb.Property == "__ancestor__" { | 224 if sb.Property == "" || sb.Property == "__ancestor__" { |
| 225 return false | 225 return false |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 return true | 228 return true |
| 229 } | 229 } |
| 230 | 230 |
| 231 // YAMLString returns the YAML representation of this IndexDefinition. | 231 // YAMLString returns the YAML representation of this IndexDefinition. |
| 232 // | 232 // |
| 233 // If the index definition is Builtin() or not Compound(), this will return | 233 // If the index definition is Builtin() or not Compound(), this will return |
| 234 // an error. | 234 // an error. |
| 235 func (id *IndexDefinition) YAMLString() (string, error) { | 235 func (id *IndexDefinition) YAMLString() (string, error) { |
| 236 if id.Builtin() || !id.Compound() { | 236 if id.Builtin() || !id.Compound() { |
| 237 » » return "", fmt.Errorf("cannot generate YAML for this IndexDefini tion") | 237 » » return "", fmt.Errorf("cannot generate YAML for %s", id) |
| 238 } | 238 } |
| 239 | 239 |
| 240 ret := bytes.Buffer{} | 240 ret := bytes.Buffer{} |
| 241 | 241 |
| 242 first := true | 242 first := true |
| 243 ws := func(s string, indent int) { | 243 ws := func(s string, indent int) { |
| 244 nl := "\n" | 244 nl := "\n" |
| 245 if first { | 245 if first { |
| 246 nl = "" | 246 nl = "" |
| 247 first = false | 247 first = false |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 } | 291 } |
| 292 for _, sb := range id.SortBy { | 292 for _, sb := range id.SortBy { |
| 293 wr('/') | 293 wr('/') |
| 294 if sb.Descending { | 294 if sb.Descending { |
| 295 wr('-') | 295 wr('-') |
| 296 } | 296 } |
| 297 ws(sb.Property) | 297 ws(sb.Property) |
| 298 } | 298 } |
| 299 return ret.String() | 299 return ret.String() |
| 300 } | 300 } |
| OLD | NEW |