aeds

package module
v0.0.0-...-9208368 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: Unlicense Imports: 9 Imported by: 0

README

aeds

App Engine datastore utilities for Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache(c context.Context, e Entity) error

ClearCache explicitly clears any memcache entries associated with this entity. One doesn't usually call this function directly. Rather, it's called implicitly when other aeds functions know the cache should be cleared.

func Delete

func Delete(c context.Context, e Entity) error

Delete removes an entity from the datastore.

func Get

func Get(c context.Context, e Entity) error

Get retrieves an entity directly from the datastore, skipping all caches. Most code should use FromId but Get can be helpful inside datastore transactions where caching would interfere.

Get automatically calls IdempotentReset, if applicable, to handle retrying transactions.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

Returns true if the given error is a datastore deadline exceeded error

func IsErrFieldMismatch

func IsErrFieldMismatch(err error) bool

IsErrFieldMismatch returns whether err is a datastore.ErrFieldMismatch. This error happens when loading an entity from the datastore into a struct which doesn't have all the necessary fields.

It happens routinely when struct definitions change by removing a field.

func Key

func Key(c context.Context, e Entity) *datastore.Key

Key returns a datastore key for this entity.

func Modify

func Modify(c context.Context, e Entity, f func(Entity) error) error

Modify atomically executes a read, modify, write operation on a single entity. It should be used any time the results of a datastore read influence the contents of a datastore write. Before executing f, the contents of e will be overwritten with the latest data available from the datastore.

f should return an error value if something goes wrong with the modification. Modify returns that error value.

As always, hooks defined by HookAfterGet() and HookBeforePut() are automatically executed at the appropriate time. Be sure to define IdempotentReset() if your entity has any slice properties.

You should not perform any datastore operations inside f. By design, it doesn't have access to the transactional context used internally. Other datastore changes will happen, even if the transaction fails to commit.

func Put

func Put(c context.Context, e Entity) (*datastore.Key, error)

Put stores an entity in the datastore.

func PutMulti

func PutMulti(c context.Context, es []Entity) ([]*datastore.Key, error)

PutMulti stores many entities in the datastore.

Types

type CanBeCached

type CanBeCached interface {
	// CacheTtl indicates how long the entity should be cached in memcache.
	// Return zero to disable memcache.  If this method returns a non-zero
	// duration, the receiver should also implement the GobEncoder and
	// GobDecoder interfaces.
	CacheTtl() time.Duration
}

CanBeCached is implemented by any Entity that wants to have its values stored in memcache to improve read performance.

type Entity

type Entity interface {
	Kind() string
	StringId() string
}

interface for structures that can be stored in App Engine's datastore

func FromId

func FromId(c context.Context, e Entity) (Entity, error)

FromId fetches an entity based on its ID. The given entity should have enough data to calculate the entity's key. On success, the entity is modified in place with all data from the datastore. Field mismatch errors are ignored.

type HasGetHook

type HasGetHook interface {
	HookAfterGet()
}

HasGetHook is implemented by any Entity that wants to execute specific code after fetching the raw entity from datastore. This is often used to calculate derived fields.

type HasPutHook

type HasPutHook interface {
	HookBeforePut()
}

HasPutHook is implemented by any Entity that wants to execute specific code before writing the raw entity to datastore. This is often used to calculate derived fields.

type NeedsIdempotentReset

type NeedsIdempotentReset interface {
	IdempotentReset()
}

NeedsIdempotentReset is implemented by any Entity that needs to reset its fields to zero when performing datastore read operations that are intended to be idempotent. For example, a datastore read into a slice property is not idempotent (it just appends property values to the slice). In that case, this method might manually reset the slice length to 0 so that append leaves only the desired data.

type Sequence

type Sequence struct {
	// Name is a unique name for this sequence
	Name string

	// Minimum specifies the smallest value the sequence is allowed to hold.
	Minimum int64

	// Maximum specifies the largest value the sequence is allowed to hold.
	// Consider using math.MaxInt64
	Maximum int64

	// Start specifies the first value of this sequence.  It's used when fetching
	// the next value on a sequence which hasn't been stored in the datastore yet.
	Start int64

	// Increment specifies which value is added to the current sequence value
	// to obtain the next sequence value.  Both positive and negative numbers
	// are allowed.
	Increment int64
}

Sequence represents a sequence of int64 values which are assigned atomically and sequentially. The current value of a sequence is stored in datastore within the kind "sequences".

func (Sequence) Current

func (self Sequence) Current(c context.Context) int64

Current returns the current value of the sequence or panics if the sequence has no value yet.

func (Sequence) MaybeCurrent

func (self Sequence) MaybeCurrent(c context.Context) (int64, bool)

MaybeCurrent returns the current value of the sequence or false if the sequence has no value yet.

func (Sequence) Next

func (self Sequence) Next(c context.Context) int64

Next fetches the next value in the sequence and stores it as the current value in datastore. This method should only be called from inside a datastore transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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