OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 // Package dumper implements a very VERY dumb datastore-dumping debugging aid. | 5 // Package dumper implements a very VERY dumb datastore-dumping debugging aid. |
6 // You shouldn't plan on having this work with the production datastore with any | 6 // You shouldn't plan on having this work with the production datastore with any |
7 // appreciable amount of data. | 7 // appreciable amount of data. |
8 // | 8 // |
9 // This will take an arbitrary query (or even a query for every entity in the | 9 // This will take an arbitrary query (or even a query for every entity in the |
10 // entire datastore), and print every entity to some output stream. | 10 // entire datastore), and print every entity to some output stream. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return prop.String() | 79 return prop.String() |
80 } | 80 } |
81 | 81 |
82 prnt := func(format string, args ...interface{}) (err error) { | 82 prnt := func(format string, args ...interface{}) (err error) { |
83 var amt int | 83 var amt int |
84 amt, err = fmt.Fprintf(out, format, args...) | 84 amt, err = fmt.Fprintf(out, format, args...) |
85 n += amt | 85 n += amt |
86 return | 86 return |
87 } | 87 } |
88 | 88 |
89 » prop := func(kind, name string, vals []datastore.Property) (err error) { | 89 » prop := func(kind, name string, pdata datastore.PropertyData) (err error
) { |
90 » » if len(vals) <= 1 { | 90 » » switch t := pdata.(type) { |
91 » » » return prnt(" %q: [%s]\n", name, fmtVal(kind, name, val
s[0])) | 91 » » case datastore.Property: |
92 » » } | 92 » » » return prnt(" %q: %s\n", name, fmtVal(kind, name, t)) |
93 » » if err = prnt(" %q: [\n %s", name, fmtVal(kind, name, vals[0
])); err != nil { | 93 |
94 » » » return | 94 » » case datastore.PropertySlice: |
95 » » } | 95 » » » if len(t) <= 1 { |
96 » » for _, v := range vals[1:] { | 96 » » » » return prnt(" %q: [%s]\n", name, fmtVal(kind, n
ame, t[0])) |
97 » » » if err = prnt(",\n %s", fmtVal(kind, name, v)); err !
= nil { | 97 » » » } |
| 98 » » » if err = prnt(" %q: [\n %s", name, fmtVal(kind, name
, t[0])); err != nil { |
98 return | 99 return |
99 } | 100 } |
| 101 for _, v := range t[1:] { |
| 102 if err = prnt(",\n %s", fmtVal(kind, name, v)
); err != nil { |
| 103 return |
| 104 } |
| 105 } |
| 106 |
| 107 default: |
| 108 return fmt.Errorf("unknown PropertyData %T", t) |
100 } | 109 } |
101 return prnt("\n ]\n") | 110 return prnt("\n ]\n") |
102 } | 111 } |
103 | 112 |
104 err = ds.Run(q, func(pm datastore.PropertyMap) error { | 113 err = ds.Run(q, func(pm datastore.PropertyMap) error { |
105 key := datastore.GetMetaDefault(pm, "key", nil).(*datastore.Key) | 114 key := datastore.GetMetaDefault(pm, "key", nil).(*datastore.Key) |
106 if !cfg.WithSpecial && strings.HasPrefix(key.Kind(), "__") && st
rings.HasSuffix(key.Kind(), "__") { | 115 if !cfg.WithSpecial && strings.HasPrefix(key.Kind(), "__") && st
rings.HasSuffix(key.Kind(), "__") { |
107 return nil | 116 return nil |
108 } | 117 } |
109 if err := prnt("\n%s:\n", key); err != nil { | 118 if err := prnt("\n%s:\n", key); err != nil { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // default rendering. | 151 // default rendering. |
143 func Query(c context.Context, q *datastore.Query) { | 152 func Query(c context.Context, q *datastore.Query) { |
144 Config{}.Query(c, q) | 153 Config{}.Query(c, q) |
145 } | 154 } |
146 | 155 |
147 // All dumps all entities to stdout without special entities and with default | 156 // All dumps all entities to stdout without special entities and with default |
148 // rendering. | 157 // rendering. |
149 func All(c context.Context) { | 158 func All(c context.Context) { |
150 Config{}.Query(c, nil) | 159 Config{}.Query(c, nil) |
151 } | 160 } |
OLD | NEW |