import "go.chromium.org/luci/gae/service/datastore/dumper"
Package dumper implements a very VERY dumb datastore-dumping debugging aid. You shouldn't plan on having this work with the production datastore with any appreciable amount of data.
This will take an arbitrary query (or even a query for every entity in the entire datastore), and print every entity to some output stream.
All dumps all entities to stdout without special entities and with default rendering.
Query dumps the provided query to stdout without special entities and with default rendering.
type Config struct { // OutStream is the output stream to use. If this is nil, os.Stdout will be // used. OutStream io.Writer // WithSpecial, if true, includes entities which have kinds that begin and // end with "__". By default, these entities are skipped. WithSpecial bool // PropFilters is an optional property filter map for controlling the // rendering of certain Kind/Property values. PropFilters PropFilterMap // KindFilters is an optional kind filter for controlling the rendering of // certain Kind values. KindFilters KindFilterMap }
Config is a configured dumper.
Query will dump everything matching the provided query.
If the provided query is nil, a kindless query without any filters will be used.
Code:
package main
import (
"fmt"
"go.chromium.org/luci/gae/impl/memory"
ds "go.chromium.org/luci/gae/service/datastore"
"golang.org/x/net/context"
)
type ExampleModel struct {
Kind string `gae:"$kind,Example"`
ID int64 `gae:"$id"`
Parent *ds.Key `gae:"$parent"`
Vals []string
Number int64
HexNumber int64
}
func main() {
c := context.Background()
c = memory.Use(c)
root := ds.MakeKey(c, "Parent", 1)
models := []*ExampleModel{
{ID: 1, Vals: []string{"hi", "there"}, Number: 10, HexNumber: 20},
{ID: 2, Vals: []string{"other"}, Number: 11, HexNumber: 21},
{ID: 1, Parent: root, Vals: []string{"child", "ent"}},
{Kind: "Other", ID: 1, Vals: []string{"other"}, Number: 11, HexNumber: 21},
}
if err := ds.Put(c, models); err != nil {
panic(err)
}
// indexes must be up-to-date here.
ds.GetTestable(c).CatchupIndexes()
_, err := Config{
PropFilters: PropFilterMap{
{"Example", "HexNumber"}: func(p ds.Property) string {
return fmt.Sprintf("0x%04x", p.Value())
},
},
KindFilters: KindFilterMap{
"Other": func(key *ds.Key, pm ds.PropertyMap) string {
return "I AM A BANANA"
},
},
}.Query(c, nil)
if err != nil {
panic(err)
}
}
Key is a key into a PropFilterMap
KindFilterMap maps from a Kind to a formatting function. You may use this to specially format particular Kinds. If this function returns an empty string, the default formatting function (including any PropFilterMap entries) will be used.
A PropFilterMap maps from Kind+PropertyName tuples to a formatting function. You may use this to specially format particular properties.
Package dumper imports 7 packages (graph). Updated 2021-01-23. Refresh now. Tools for package owners.