gae: go.chromium.org/gae/service/datastore/dumper Index | Examples | Files

package dumper

import "go.chromium.org/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.

Index

Examples

Package Files

dumper.go

func All Uses

func All(c context.Context)

All dumps all entities to stdout without special entities and with default rendering.

func Query Uses

func Query(c context.Context, q *ds.Query)

Query dumps the provided query to stdout without special entities and with default rendering.

type Config Uses

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 Uses

func (cfg Config) Query(c context.Context, q *ds.Query) (n int, err error)

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/gae/impl/memory"
    ds "go.chromium.org/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)
    }

}

type Key Uses

type Key struct {
    Kind     string
    PropName string
}

Key is a key into a PropFilterMap

type KindFilterMap Uses

type KindFilterMap map[string]func(*ds.Key, ds.PropertyMap) string

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.

type PropFilterMap Uses

type PropFilterMap map[Key]func(ds.Property) string

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 2018-08-15. Refresh now. Tools for package owners.