ds

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 11 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchEntity      = errors.New("dsprovider: no such entity")
	ErrFieldMismatch     = errors.New("dsprovider: src obj had a field that dst obj didn't")
	ErrNoMemcacheService = errors.New("dsprovider: no memcache service available")
)
View Source
var Debug = false

Functions

func SetProvider

func SetProvider(ctx context.Context, p DatastoreProvider) context.Context

SetProvider embeds a provider inside a Context, for later retrieval

Types

type CloudDSProvider

type CloudDSProvider struct {
	Project string
	// contains filtered or unexported fields
}

CloudDSProvider implements the DatastoreProvider interface using the cloud datastore API, for use outside of appengine environments.

func NewCloudDSProvider

func NewCloudDSProvider(ctx context.Context, project string) (*CloudDSProvider, error)

func (CloudDSProvider) Criticalf

func (p CloudDSProvider) Criticalf(ctx context.Context, format string, args ...interface{})

func (CloudDSProvider) Debugf

func (p CloudDSProvider) Debugf(ctx context.Context, format string, args ...interface{})

func (CloudDSProvider) DecodeKey

func (p CloudDSProvider) DecodeKey(encoded string) (Keyer, error)

func (CloudDSProvider) Delete

func (p CloudDSProvider) Delete(ctx context.Context, keyer Keyer) error

func (CloudDSProvider) DeleteMulti

func (p CloudDSProvider) DeleteMulti(ctx context.Context, keyers []Keyer) error

func (CloudDSProvider) Errorf

func (p CloudDSProvider) Errorf(ctx context.Context, format string, args ...interface{})

func (CloudDSProvider) Get

func (p CloudDSProvider) Get(ctx context.Context, keyer Keyer, dst interface{}) error

func (CloudDSProvider) GetAll

func (p CloudDSProvider) GetAll(ctx context.Context, q *Query, dst interface{}) ([]Keyer, error)

func (CloudDSProvider) GetMulti

func (p CloudDSProvider) GetMulti(ctx context.Context, keyers []Keyer, dst interface{}) error

func (CloudDSProvider) HTTPClient

func (p CloudDSProvider) HTTPClient(ctx context.Context) *http.Client

func (CloudDSProvider) Infof

func (p CloudDSProvider) Infof(ctx context.Context, format string, args ...interface{})

func (CloudDSProvider) KeyName

func (p CloudDSProvider) KeyName(in Keyer) string

func (CloudDSProvider) KeyParent

func (p CloudDSProvider) KeyParent(in Keyer) Keyer

func (CloudDSProvider) NewIDKey

func (p CloudDSProvider) NewIDKey(ctx context.Context, kind string, id int64, root Keyer) Keyer

func (CloudDSProvider) NewIncompleteKey

func (p CloudDSProvider) NewIncompleteKey(ctx context.Context, kind string, root Keyer) Keyer

func (CloudDSProvider) NewNameKey

func (p CloudDSProvider) NewNameKey(ctx context.Context, kind, name string, root Keyer) Keyer

func (CloudDSProvider) Put

func (p CloudDSProvider) Put(ctx context.Context, keyer Keyer, src interface{}) (Keyer, error)

func (CloudDSProvider) PutMulti

func (p CloudDSProvider) PutMulti(ctx context.Context, keyers []Keyer, src interface{}) ([]Keyer, error)

func (CloudDSProvider) Warningf

func (p CloudDSProvider) Warningf(ctx context.Context, format string, args ...interface{})

type DatastoreProvider

type DatastoreProvider interface {
	Get(ctx context.Context, keyer Keyer, dst interface{}) error
	GetMulti(ctx context.Context, keyers []Keyer, dst interface{}) error
	GetAll(ctx context.Context, q *Query, dst interface{}) ([]Keyer, error)
	Put(ctx context.Context, keyer Keyer, src interface{}) (Keyer, error)
	PutMulti(ctx context.Context, keyers []Keyer, src interface{}) ([]Keyer, error)
	Delete(ctx context.Context, keyer Keyer) error
	DeleteMulti(ctx context.Context, keyers []Keyer) error

	NewIncompleteKey(ctx context.Context, kind string, root Keyer) Keyer
	NewNameKey(ctx context.Context, kind, name string, root Keyer) Keyer
	NewIDKey(ctx context.Context, kind string, id int64, root Keyer) Keyer
	DecodeKey(encoded string) (Keyer, error)
	KeyParent(Keyer) Keyer
	KeyName(Keyer) string

	// HTTP client - maybe urlfetch, maybe not
	HTTPClient(ctx context.Context) *http.Client

	// Logging support - goes to appengine logging, or maybe STDOUT
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
	Criticalf(ctx context.Context, format string, args ...interface{})
}

Provider is a wrapper over the datastore APIs (cloud and appengine), so that client code (and in particular query assembley) can run both inside and outside of google appengine.

In fact, it wraps all the appengine APIs (incl. /log and /urlfetch), so we don't need to worry about any appengine libs except in util/ae/ds.

func GetProviderOrPanic

func GetProviderOrPanic(ctx context.Context) DatastoreProvider

GetProvider retrieves the provider from the context; panics if not found

type Filter

type Filter struct {
	Field string
	Value interface{}
}

type Iterator

type Iterator struct {
	PageSize int

	Slice interface{} // The current page of results
	// contains filtered or unexported fields
}

Iterator is a batching iterator that executes the full query up front, to get a list of all keys; then it fetches pages of results as it works through the keys. We don't use datastore.Iterator, as it times out the result set after 60 seconds, out of abundance of caution.

func NewIterator

func NewIterator(ctx context.Context, p DatastoreProvider, q *Query, obj interface{}) *Iterator

Snarf down all the keys from the get go.

func (*Iterator) Err

func (iter *Iterator) Err() error

func (*Iterator) Iterate

func (iter *Iterator) Iterate(ctx context.Context) bool

func (*Iterator) Remaining

func (iter *Iterator) Remaining() int

Remaining returns how many items are yet to be processed by the caller

func (*Iterator) SetErr

func (iter *Iterator) SetErr(err error)

Convenience function for things that wrap iterator

func (*Iterator) Val

func (iter *Iterator) Val(dst interface{}) Keyer

func (*Iterator) ValAsInterface

func (iter *Iterator) ValAsInterface() interface{}

ValAsInterface returns the val as the base interface; it will need a type assertion back into the relevant type.

type Keyer

type Keyer interface {
	Encode() string
}

Keyer is a very thin wrapper. It should be populated with a *datastore.Key

type Query

type Query struct {
	Kind          string
	AncestorKeyer Keyer
	Filters       []Filter
	ProjectFields []string
	OrderStr      string
	LimitVal      int
	KeysOnlyVal   bool
	DistinctVals  bool
}

Query is a thin skin over the datastore query API. It also provides a textual dump of the query.

func NewQuery

func NewQuery(kind string) *Query

func (*Query) Ancestor

func (q *Query) Ancestor(keyer Keyer) *Query

func (*Query) Distinct

func (q *Query) Distinct() *Query

func (*Query) Filter

func (q *Query) Filter(field string, val interface{}) *Query

func (*Query) KeysOnly

func (q *Query) KeysOnly() *Query

func (*Query) Limit

func (q *Query) Limit(l int) *Query

func (*Query) Order

func (q *Query) Order(o string) *Query

func (*Query) Project

func (q *Query) Project(fields ...string) *Query

func (*Query) String

func (q *Query) String() string

Jump to

Keyboard shortcuts

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