Documentation
Overview ¶
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.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
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.
func (Config) Query ¶
Query will dump everything matching the provided query.
If the provided query is nil, a kindless query without any filters will be used.
Example ¶
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)
}
}
dev~app::/Example,1: "HexNumber": 0x0014 "Number": PTInt(10) "Vals": [ PTString("hi"), PTString("there") ] dev~app::/Example,2: "HexNumber": 0x0015 "Number": PTInt(11) "Vals": [PTString("other")] dev~app::/Other,1: I AM A BANANA dev~app::/Parent,1/Example,1: "HexNumber": 0x0000 "Number": PTInt(0) "Vals": [ PTString("child"), PTString("ent") ]
type KindFilterMap ¶
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.