dumper

package
v0.0.0-...-d3da680 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

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

func All

func All(c context.Context)

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

func Query

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

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

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

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.

Example
package main

import (
	"context"
	"fmt"

	"go.chromium.org/luci/gae/impl/memory"
	ds "go.chromium.org/luci/gae/service/datastore"
)

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)
	}

}
Output:

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 Key

type Key struct {
	Kind     string
	PropName string
}

Key is a key into a PropFilterMap

type KindFilterMap

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL