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

Unified Diff: service/datastore/index.go

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: symbollls 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
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/index_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/index.go
diff --git a/service/datastore/index.go b/service/datastore/index.go
index d06bd9067f2a9f06991ca6559c3a4745896c7f15..db49d2fe85b08814dd81de8e0e1f055dc8ac7153 100644
--- a/service/datastore/index.go
+++ b/service/datastore/index.go
@@ -228,8 +228,43 @@ 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{}
+
+ first := true
+ ws := func(s string, indent int) {
+ nl := "\n"
+ if first {
+ nl = ""
+ first = false
+ }
+ fmt.Fprintf(&ret, "%s%s%s", nl, strings.Repeat(" ", indent), s)
+ }
+
+ ws(fmt.Sprintf("- kind: %s", id.Kind), 0)
+ if id.Ancestor {
+ ws("ancestor: yes", 1)
+ }
+ ws("properties:", 1)
+ for _, o := range id.SortBy {
+ ws(fmt.Sprintf("- name: %s", o.Property), 1)
+ if o.Descending {
+ ws("direction: desc", 2)
+ }
+ }
+ return ret.String(), nil
+}
+
func (id *IndexDefinition) String() string {
- ret := &bytes.Buffer{}
+ ret := bytes.Buffer{}
wr := func(r rune) {
_, err := ret.WriteRune(r)
if err != nil {
« no previous file with comments | « pre-commit-go.yml ('k') | service/datastore/index_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698