Documentation ¶
Overview ¶
Package aedstorm an ORM like functions which makes working with App Engine datastore entities in go a bit easier
Index ¶
- Constants
- Variables
- func Copy(srcVal interface{}, dstVal interface{}) error
- func SetMockQueryResult(data interface{}, err error, keys []*datastore.Key)
- type DataModel
- func (dm *DataModel) Cache() error
- func (dm *DataModel) Context() context.Context
- func (dm *DataModel) Delete() error
- func (dm *DataModel) ID() string
- func (dm *DataModel) Key() *datastore.Key
- func (dm *DataModel) Load() error
- func (dm *DataModel) Save() error
- func (dm *DataModel) Uncache() error
- func (dm *DataModel) WithContext(ctx context.Context) *DataModel
- type EntityError
- type EntityID
- type EntityName
- type Model
- type OnCache
- type OnDelete
- type OnSave
- type OnUncache
- type Query
- func (q *Query) Count(ctx context.Context) (int, error)
- func (q *Query) Filter(filterStr string, value interface{}) *Query
- func (q *Query) GetAll(ctx context.Context, out interface{}) ([]*datastore.Key, error)
- func (q *Query) KeysOnly() *Query
- func (q *Query) Limit(num int) *Query
- func (q *Query) Offset(num int) *Query
- func (q *Query) Order(fieldName string) *Query
- type SetID
- type UUID
Constants ¶
const (
// TagName is the tag name where we look for custom tag values, like "id"
TagName = "datastore"
)
Variables ¶
var ( ErrNoModel = errors.New("Model is not loaded") ErrNoID = errors.New("Model has no ID") ErrNoContext = errors.New("No net/context was loaded") ErrNilModel = errors.New("Model is nil") ErrModelInvalid = errors.New("Model must be a struct pointer") )
Standardized error messages
Functions ¶
func Copy ¶
func Copy(srcVal interface{}, dstVal interface{}) error
Copy copies one interface into the other doing type checking to make sure it's safe. If it cannot be copied, an error is returned.
func SetMockQueryResult ¶
SetMockQueryResult sets the query GetAll() result to be the values given
Types ¶
type DataModel ¶
DataModel is a ORM styled structure for saving and loading entities
func (*DataModel) ID ¶
ID returns the underlying data struct's unique ID. If the supplied struct implements this interface, then it's result will be that of the model's EntityID() function. Otherwise, a new random uuid v4 will be used.
func (*DataModel) Load ¶
Load loads the entity from the datastore. Must have an ID for this to work.
type EntityError ¶
type EntityError interface {
Error() error
}
EntityError is an interface which returns an error. When the model's struct implements this, it's called before saving the struct to the datastore. It can be used for verification of the data in the model, etc.
type EntityID ¶
type EntityID interface {
GetID() string
}
EntityID is an interface returns the int64 ID for the datastore struct. If the supplied struct implements this interface, then it's result will be the ID of the struct in the datastore. Otherwise, a new random uuid v4 will be used
type EntityName ¶
type EntityName interface {
Entity() string
}
EntityName is an interface which defines the entity name of the data to be stored in the datastore. If a struct implements this interface, then it will be saved with this entity name. If not, the name of the struct itself will be used.
type Model ¶
type Model interface{}
Model is an interface for datastore entities. User-implemented structs must implement this interface for things to work.
type OnCache ¶
type OnCache interface {
Cache() error
}
OnCache is an interface which defines a callback which is run after a entity is successfully cached.
type OnDelete ¶
type OnDelete interface {
Delete() error
}
OnDelete is an interface which defines a callback which is run after a entity is successfully deleted.
type OnSave ¶
type OnSave interface {
Save() error
}
OnSave is an interface which defines a callback which is run after a entity is successfully saved. It's run parallel with the caching method, so there's no guarantee that the model is already in memcache when it's called. Instead, if you need to rely on it being in memcache, implement the OnCache interface.
type OnUncache ¶
type OnUncache interface {
Uncache() error
}
OnUncache is an interface which defines a callback which is run after a entity is successfully removed from cache.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a struct which implements a subset of the "datastore.Query" interface and is mockable
func NewQuery ¶
func NewQuery(m interface{}) *Query
NewQuery returns a new query based off the type of m. If m implements the EntityName interface, it uses that for an entity name, otherwise it uses the name of the struct itself