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

Unified Diff: service/datastore/index.go

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: Created 5 years, 3 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 d06bd9067f2a9f06991ca6559c3a4745896c7f15..9b7aef02e98a438d921a702768514ed1982dd085 100644
--- a/service/datastore/index.go
+++ b/service/datastore/index.go
@@ -228,6 +228,48 @@ func (id *IndexDefinition) Compound() bool {
return true
}
+// YAMLString returns the YAML representation of this IndexDefinition.
+//
+// If the index definition is Builtin() or not Compound(), this will return
+// an error.
+func (id *IndexDefinition) YAMLString() (string, error) {
+ if id.Builtin() || !id.Compound() {
+ return "", fmt.Errorf("cannot generate YAML for this IndexDefinition")
+ }
+
+ ret := &bytes.Buffer{}
Vadim Sh. 2015/09/24 19:17:29 nit: just bytes.Buffer{}, no need for dynamic allo
iannucci 2015/09/24 19:52:34 Common misconception: there's no actual difference
Vadim Sh. 2015/09/24 19:57:50 """In the current compilers, if a variable has its
iannucci 2015/09/24 20:12:59 it made more sense before I had the ws function. t
+ indent := 0
+
+ first := true
+ ws := func(s string) {
+ nl := "\n"
+ if first {
+ nl = ""
+ first = false
+ }
+ _, err := fmt.Fprintf(ret, "%s%s%s", nl, strings.Repeat(" ", indent), s)
+ if err != nil {
Vadim Sh. 2015/09/24 19:17:29 just remove errcheck from pre-commit-go.yml >_< Ch
iannucci 2015/09/24 19:52:34 lol ok
+ panic(err)
+ }
+ }
+
+ ws(fmt.Sprintf("- kind: %s", id.Kind))
+ indent++
+ if id.Ancestor {
+ ws("ancestor: yes")
+ }
+ ws("properties:")
+ for _, o := range id.SortBy {
+ ws(fmt.Sprintf("- name: %s", o.Property))
+ if o.Descending {
+ indent++
Vadim Sh. 2015/09/24 19:17:29 :) just pass indent explicitly, e.g. ws("properti
iannucci 2015/09/24 19:52:35 done :)
+ ws("direction: desc")
+ indent--
+ }
+ }
+ return ret.String(), nil
+}
+
func (id *IndexDefinition) String() string {
ret := &bytes.Buffer{}
wr := func(r rune) {

Powered by Google App Engine
This is Rietveld 408576698