Documentation ¶
Index ¶
- func ClearCache(c context.Context, e Entity) error
- func Delete(c context.Context, e Entity) error
- func Get(c context.Context, e Entity) error
- func IsDeadlineExceeded(err error) bool
- func IsErrFieldMismatch(err error) bool
- func Key(c context.Context, e Entity) *datastore.Key
- func Modify(c context.Context, e Entity, f func(Entity) error) error
- func Put(c context.Context, e Entity) (*datastore.Key, error)
- func PutMulti(c context.Context, es []Entity) ([]*datastore.Key, error)
- type CanBeCached
- type Entity
- type HasGetHook
- type HasPutHook
- type NeedsIdempotentReset
- type Sequence
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearCache ¶
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 Get ¶
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 ¶
Returns true if the given error is a datastore deadline exceeded error
func IsErrFieldMismatch ¶
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 Modify ¶
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.
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 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 ¶
Current returns the current value of the sequence or panics if the sequence has no value yet.
func (Sequence) MaybeCurrent ¶
MaybeCurrent returns the current value of the sequence or false if the sequence has no value yet.