Documentation ¶
Overview ¶
Package anom is a simple "object mapper" for appengine datastore and that provides some convenience functions for dealing with datastore entities.
package app import ( "github.com/Bogdanp/anom" ) type Post struct { anom.Meta Title string Content string }
Index ¶
Constants ¶
View Source
const ( // StateActive is the state of Model instances that have been persisted. StateActive = "active" // StateDeleted is the state of Model instances that have been deleted. StateDeleted = "deleted" )
Variables ¶
View Source
var ( // ErrMissingKey is the error that is returned when a Model lacks a // key. This can be returned if you attempt to Delete a Model that // hasn't been saved yet or if you attempt to Get a Model that // doesn't have a Key. ErrMissingKey = errors.New("anom: model does not have a Key") )
Functions ¶
Types ¶
type Meta ¶
type Meta struct { Key *datastore.Key `json:"-" datastore:"-"` Parent *datastore.Key `json:"-" datastore:"-"` State string `json:"-"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt time.Time `json:"deletedAt"` }
Meta is the struct that all Model structs must embed. It extends entities with metadata about when they were created, last updated and deleted as well as their current state and their Key.
type User struct { anom.Meta Username string }
type Model ¶
type Model interface {
// contains filtered or unexported methods
}
Model is the interface that all Model structs automatically implement when they embed Meta.
type Option ¶
type Option func(Model)
Option is the type of functional Model options.
func WithIntID ¶
WithIntID is an Option for assigning a datastore Key with the given int64 id to a Model's Meta.
func WithParent ¶
WithParent is an Option for assigning a datastore Key to a Model's Meta as that Model's parent.
p := &Post{Content: "Hello"} Put(ctx, p, WithParent(u.Key))
Click to show internal directories.
Click to hide internal directories.